Purge All Tool in AutoCAD API it is running but not working

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
private static int PurgeDatabase(Database db)
{
int idCount = 0;
Document doc =
Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
using (DocumentLock dc = doc.LockDocument())
{
Transaction tr =
db.TransactionManager.StartTransaction();
using (tr)
{
// Create the list of objects to "purge"
ObjectIdCollection idsToPurge =
new ObjectIdCollection();
// Add all the Registered Application names
RegAppTable rat =
(RegAppTable)tr.GetObject(
db.RegAppTableId,
OpenMode.ForRead
);
foreach (ObjectId raId in rat)
{
if (raId.IsValid)
{
idsToPurge.Add(raId);
}
}
// Call the Purge function to filter the list
db.Purge(idsToPurge);
Editor ed = doc.Editor;
ed.WriteMessage(
"\nRegistered applications being purged: "
);
// Erase each of the objects we've been
// allowed to
foreach (ObjectId id in idsToPurge)
{
DBObject obj =
tr.GetObject(id, OpenMode.ForWrite);
// Let's just add to me "debug" code
// to list the registered applications
// we're erasing
RegAppTableRecord ratr =
obj as RegAppTableRecord;
if (ratr != null)
{
ed.WriteMessage(
"\"{0}\" ",
ratr.Name
);
}
obj.Erase();
}
// Return the number of objects erased
// (i.e. purged)
idCount = idsToPurge.Count;
tr.Commit();
}
}
return idCount;
}