Skip to content

Instantly share code, notes, and snippets.

@chuongmep
Last active Jun 8, 2020
Embed
What would you like to do?
Purge CAD
public static void PurgesCAD()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction Tx = db.TransactionManager.StartTransaction())
{
BlockTable table = Tx.GetObject(db.BlockTableId,
OpenMode.ForRead) as BlockTable;
ObjectIdCollection blockIds = new ObjectIdCollection();
do
{
blockIds.Clear();
foreach (ObjectId id in table)
blockIds.Add(id);
db.Purge(blockIds);
foreach (ObjectId id in blockIds)
{
DBObject obj = Tx.GetObject(id, OpenMode.ForWrite);
obj.Erase();
}
}
while (blockIds.Count != 0);
Tx.Commit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment