.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Attach PDF or RasterImage Reload

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
mnav
1444 Views, 3 Replies

Attach PDF or RasterImage Reload

Hi

  Is there any Functionality available for Reloading the PDF or Image like we have for DWGs (Database.ReloadXrefs).

Thanks

3 REPLIES 3
Message 2 of 4
norman.yuan
in reply to: mnav

Both PdfDefinition and RasterImageDef class has Load() and Unload() methods (their signature are slightly different, though).

 

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.

 

To get all PdfDefinition in a drawing, I used code like this:

 

 

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;
        }

 Then, I use this code to get unloaded PdfDefinitions (ObjectIdCollection):

 

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;
        }

 Then I can do reload by passing the ObjectIdCollection obtained from GetUnloadedPdfDefs():

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();
                }
            }
        }

 After calling ReloadPdf(), you would need to call Editor.Regen() to make the reloaded Pdf underlay to show up on screen.

 

Message 3 of 4
mnav
in reply to: norman.yuan

Thanks norman.yuan for your help. i was calling the load function but missing the regen of drwing. that solved the problem.

Thanks a lot once again.

 

 

Message 4 of 4

Thank you norman.yuan, I have been looking for this as well.

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost