Below code shows the use of “Explode” API to explode the block reference through API. Explode API will return array of non database resident DBObject. If required, the DBObject array return from “Explode” API can be added to database.
[CommandMethod("explodeRef")]
static public void explodeRef()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityOptions options =
new PromptEntityOptions("nSelect block reference");
options.SetRejectMessage("nSelect only block reference");
options.AddAllowedClass(typeof(BlockReference), false);
PromptEntityResult acSSPrompt =
ed.GetEntity(options);
using (Transaction tx =
db.TransactionManager.StartTransaction())
{
BlockReference blockRef = tx.GetObject(acSSPrompt.ObjectId,
OpenMode.ForRead) as BlockReference;
DBObjectCollection entitySet = new DBObjectCollection();
blockRef.Explode(entitySet);
BlockTableRecord table = (BlockTableRecord)tx.GetObject(
db.CurrentSpaceId, OpenMode.ForWrite);
foreach (DBObject obj in entitySet)
{
if (obj is Entity)
{
table.AppendEntity((Entity)obj);
tx.AddNewlyCreatedDBObject(obj, true);
}
}
tx.Commit();
}
}

Leave a Reply to B2D2Cancel reply