Identifying an xref is an attachment or overlay

By Virupaksha Aithal

Blocktable record’s “IsFromOverlayReference” property helps to identify the type of reference. Refer below code, which identifies the overlay or attachment type of reference in working document.

[CommandMethod("XrefType")]
static public void XrefType()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;
 
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        BlockTable table = tr.GetObject(db.BlockTableId,
                                    OpenMode.ForRead) as BlockTable;
 
        foreach (ObjectId id in table)
        {
            BlockTableRecord record = tr.GetObject(id,
                               OpenMode.ForRead) as BlockTableRecord;
 
            if (record.IsFromExternalReference)
            {
                if (record.IsFromOverlayReference)
                {
                    ed.WriteMessage(record.Name
                                    + " is a overlay referencen");
                }
                else
                {
                    ed.WriteMessage(record.Name
                                    + " is a attacment referencen");
                }
            }
        }
 
        tr.Commit();
    }
 
}

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading