Delete un used registered application names from database

By Virupaksha Aithal

Database.Purge API can be used to identify the un-used registered applications. Once un used registered application names are identified, use “erase” API to remove the registered application names from the drawing file.

[CommandMethod("PurgeApplicationName")]
public static void PurgeApplicationName()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;
 
    using (Transaction Tx =
           db.TransactionManager.StartTransaction())
    {
        RegAppTable table = Tx.GetObject(db.RegAppTableId,
            OpenMode.ForRead) as RegAppTable;
 
        ObjectIdCollection regIds = new ObjectIdCollection();
        foreach (ObjectId id in table)
        {
            regIds.Add(id);
        }
 
        //this function will remove all
        //app names which are used in the drawing file
        db.Purge(regIds);
 
        foreach (ObjectId id in regIds)
        {
            DBObject obj = Tx.GetObject(id, OpenMode.ForWrite);
            obj.Erase();
        }
        Tx.Commit();
    }
}

Comments

2 responses to “Delete un used registered application names from database”

  1. Joshua Hunt Avatar
    Joshua Hunt

    How is this different or better than…
    -PURGE
    REGAPPS
    *

  2. Not better – different. For example …
    – It can be used on AutoCAD versions that don’t have that purge option.
    – It demonstrates how to perform an operation using the API.

Leave a Reply to Stephen PrestonCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading