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

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

Anonymous
Not applicable
682 Views
0 Replies
Message 1 of 1

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

Anonymous
Not applicable

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;
}

0 Likes
683 Views
0 Replies
Replies (0)