<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Attach PDF or RasterImage Reload in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/attach-pdf-or-rasterimage-reload/m-p/8071526#M60107</link>
    <description>&lt;P&gt;Thank you norman.yuan, I have been looking for this as well.&lt;BR /&gt;&lt;BR /&gt;Would you by any chance also know how to set the page of a pdf reference? I haven't been able to find a related variable in the PdfDefinition and PdfReference objects.&lt;/P&gt;</description>
    <pubDate>Fri, 15 Jun 2018 17:03:22 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-06-15T17:03:22Z</dc:date>
    <item>
      <title>Attach PDF or RasterImage Reload</title>
      <link>https://forums.autodesk.com/t5/net-forum/attach-pdf-or-rasterimage-reload/m-p/3095024#M60103</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp; Is there any Functionality available for Reloading the PDF or Image like we have for DWGs (Database.ReloadXrefs).&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2011 15:47:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/attach-pdf-or-rasterimage-reload/m-p/3095024#M60103</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-07-18T15:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: Attach PDF or RasterImage Reload</title>
      <link>https://forums.autodesk.com/t5/net-forum/attach-pdf-or-rasterimage-reload/m-p/3095560#M60104</link>
      <description>&lt;P&gt;Both PdfDefinition and RasterImageDef class has Load() and Unload() methods (their signature are slightly different, though).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Take PdfDefinition as example. To reload unloaded Pdf underlay, you can loop through all Pdfdefinitions in a drawing, and test each PdfDefinition.Loaded property. If Loaded=False, then you can call PdfDefinition.Load() method to reload it. Of course, before call Load() to reload, you may want to check PdfDefinition.SourceFileName/ActiveFileName to make sure the source file still exists. If not, you may want to prompt user and/or remove the PdfDefinition and/or locate the source file and reattach it to the drawing as underlay.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To get all PdfDefinition in a drawing, I used code like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;private ObjectIdCollection GetPDFUnderlayDefs(Transaction tran)
        {
            ObjectIdCollection ids = new ObjectIdCollection();

            DBDictionary namedDic = (DBDictionary)tran.GetObject(_db.NamedObjectsDictionaryId, OpenMode.ForRead);
    

            string pdfDicKey = PdfDefinition.GetDictionaryKey(typeof(PdfDefinition));
            if (pdfDicKey != null)
            {
                if (namedDic.Contains(pdfDicKey))
                {
                    DBDictionary pdfDic = (DBDictionary)tran.GetObject(namedDic.GetAt(pdfDicKey), OpenMode.ForRead);
                    foreach (DBDictionaryEntry entry in pdfDic)
                    {
                        ObjectId id = (ObjectId)entry.Value;
                        ids.Add(id);
                    }
                }
            }
                    
            return ids;
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Then, I use this code to get unloaded PdfDefinitions (ObjectIdCollection):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public ObjectIdCollection GetUnloadedPdfDefs()
        {
            ObjectIdCollection ids = new ObjectIdCollection();

            using (_dwg.LockDocument())
            {
                using (Transaction tran = _db.TransactionManager.StartTransaction())
                {
                    ObjectIdCollection defs = GetPDFUnderlayDefs(tran);

                    foreach (ObjectId id in defs)
                    {
                        PdfDefinition def =(PdfDefinition) tran.GetObject(id, OpenMode.ForRead);
                        if (!def.Loaded) ids.Add(id);
                    }

                    tran.Commit();
                }
            }

            return ids;
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Then I can do reload by passing the ObjectIdCollection obtained from GetUnloadedPdfDefs():&lt;/P&gt;&lt;PRE&gt;public void ReloadPdf(ObjectIdCollection pdfdefIds)
        {
            using (_dwg.LockDocument())
            {
                using (Transaction tran = _db.TransactionManager.StartTransaction())
                {
                    foreach (ObjectId id in pdfdefIds)
                    {
                        PdfDefinition def = (PdfDefinition)tran.GetObject(id, OpenMode.ForWrite);
                        if (!def.Loaded) def.Load(null);
                    }

                    tran.Commit();
                }
            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;After calling ReloadPdf(), you would need to call Editor.Regen() to make the reloaded Pdf underlay to show up on screen.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2011 21:38:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/attach-pdf-or-rasterimage-reload/m-p/3095560#M60104</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2011-07-18T21:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: Attach PDF or RasterImage Reload</title>
      <link>https://forums.autodesk.com/t5/net-forum/attach-pdf-or-rasterimage-reload/m-p/3095910#M60105</link>
      <description>&lt;P&gt;Thanks norman.yuan for your help. i was calling the load function but missing the regen of drwing. that solved the problem.&lt;/P&gt;&lt;P&gt;Thanks a lot once again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2011 09:05:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/attach-pdf-or-rasterimage-reload/m-p/3095910#M60105</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-07-19T09:05:26Z</dc:date>
    </item>
    <item>
      <title>Re: Attach PDF or RasterImage Reload</title>
      <link>https://forums.autodesk.com/t5/net-forum/attach-pdf-or-rasterimage-reload/m-p/8071526#M60107</link>
      <description>&lt;P&gt;Thank you norman.yuan, I have been looking for this as well.&lt;BR /&gt;&lt;BR /&gt;Would you by any chance also know how to set the page of a pdf reference? I haven't been able to find a related variable in the PdfDefinition and PdfReference objects.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jun 2018 17:03:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/attach-pdf-or-rasterimage-reload/m-p/8071526#M60107</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-06-15T17:03:22Z</dc:date>
    </item>
  </channel>
</rss>

