List DWF underlay definitions in the drawing

By Virupaksha Aithal
Each DWF underlay definitions are stored in the named object Dictionary under Dictionary name “ACAD_DWFDEFINITIONS”. Below code shows the procedure to go through the “ACAD_DWFDEFINITIONS” Dictionary and listing all the DWF definitions.

[CommandMethod("DWFUnderlayList")]
static public void DWFUnderlayList()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;
 
    using (Transaction tr =
                    db.TransactionManager.StartTransaction())
    {
        DBDictionary nod = (DBDictionary)tr.GetObject(
                db.NamedObjectsDictionaryId, OpenMode.ForRead);
 
        string defDictKey = UnderlayDefinition.GetDictionaryKey(
                                            typeof(DwfDefinition));
 
        if (nod.Contains(defDictKey))
        {
            DBDictionary dwfDict =
                        (DBDictionary)tr.GetObject(
                           nod.GetAt(defDictKey), OpenMode.ForRead);
 
            foreach (DBDictionaryEntry entry in dwfDict)
            {
                DwfDefinition dwfDef = (DwfDefinition)tr.GetObject(
                                    entry.Value, OpenMode.ForRead);
 
                ed.WriteMessage(dwfDef.ActiveFileName + "n");
            }
        }
        else
        {
            ed.WriteMessage("No DWF underlay in the drawing filen");
        }
 
        tr.Commit();
    }
}

Comments

One response to “List DWF underlay definitions in the drawing”

  1. Is there a .NET API to implement the same funtion as “ULAYERS” in command line? or how to access layer information from a DGNDefinition?

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading