Determining block Explodable behavior

By Virupaksha Aithal
The “Explodable” property of a block will allow you to determine if block can be exploded or not. Below code prints names of the blocks which can be exploded.

[CommandMethod("FindBlockExplode")]
public void FindBlockExplode()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;
 
    using (Transaction Tx = db.TransactionManager.StartTransaction())
    {
        BlockTable bt = (BlockTable)Tx.GetObject(db.BlockTableId,
                                                  OpenMode.ForRead);
 
        foreach (ObjectId id in bt)
        {
            BlockTableRecord btr = Tx.GetObject(id,
                          OpenMode.ForRead) as BlockTableRecord;
 
            if (btr.IsLayout)
                continue;
 
            if (btr.Explodable)
            {
                ed.WriteMessage(btr.Name + "n");
            }
        }
 
        Tx.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