[CommandMethod("PurgeBlocks")]
public static void PurgeBlocks()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction Tx =
db.TransactionManager.StartTransaction())
{
BlockTable table = Tx.GetObject(db.BlockTableId,
OpenMode.ForRead) as BlockTable;
ObjectIdCollection blockIds = new ObjectIdCollection();
//using do/while loop to purge nested blocks.
do
{
blockIds.Clear();
foreach (ObjectId id in table)
blockIds.Add(id);
//this function will remove all
//blocks which are in use
db.Purge(blockIds);
foreach (ObjectId id in blockIds)
{
DBObject obj = Tx.GetObject(id, OpenMode.ForWrite);
obj.Erase();
}
} while (blockIds.Count != 0);
Tx.Commit();
}
}
