Register an application in a database for xdata access

By Virupaksha Aithal
Registered applications are stored in the AcDbRegAppTable. You may create a new
AcDbRegAppTableRecord with your application name and add it to the AcDbRegAppTable. Below code shows the procedure to add the AcDbRegAppTableRecord to AcDbRegAppTable. Note, below code takes a database as input, which could be a side database too (database which is not opened in AutoCAD editor)

Acad::ErrorStatus registerApp(AcDbDatabase* pDb, 
                                    const ACHAR * pAppName)
{
    AcDbRegAppTable* pAppTable = NULL;
    Acad::ErrorStatus es;
 
    // get the RegAppTable
    if((es = pDb->getRegAppTable(pAppTable,
                            AcDb::kForRead)) != Acad::eOk)
        return es;
 
    // if RegAppTable has application already - fine
    if(pAppTable->has(pAppName))
    {
        pAppTable->close();
        return Acad::eOk;
    }
 
    AcDbRegAppTableRecord* pAppTableRecord = 
                                new AcDbRegAppTableRecord();
    pAppTableRecord->setName(pAppName);
 
    pAppTable->upgradeOpen();
    if((es = pAppTable->add(pAppTableRecord)) != Acad::eOk)
    {
        delete pAppTableRecord;
        pAppTable->close();
        return es;
    }
 
    pAppTableRecord->close();
    pAppTable->close();
    return es;
}

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading