Finding erased entities

By Virupaksha Aithal

You can use “BlockTableRecord” API “IncludingErased” to get the block table record with erased entities. Once you have erased entities, you can unease the entities if required as shown in below code.

[CommandMethod("GetErasedEntities")]
public void GetErasedEntities()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Editor ed = doc.Editor;
    Database db = doc.Database;
 
    ObjectId ModelSpaceId =
            SymbolUtilityServices.GetBlockModelSpaceId(db);
 
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        BlockTableRecord record = tr.GetObject(ModelSpaceId,
                               OpenMode.ForRead) as BlockTableRecord;
 
        BlockTableRecord withErasedBTR = record.IncludingErased;
 
        foreach (ObjectId Id in withErasedBTR)
        {
            if (!Id.IsErased)
                continue;
 
            //un erase the entity...
 
            //GetObject, 3rd parameter openErased
            Entity ent = (Entity)tr.GetObject(Id,
                                           OpenMode.ForWrite, true);
            ent.Erase(false);
        }
        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