Last active
June 8, 2020 08:25
-
-
Save chuongmep/714c2586afe1b39ced9060775eb4efb4 to your computer and use it in GitHub Desktop.
Purge CAD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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