The following ObjectARX examples consist of two functions: createXrecord() and listXrecord(). The first function adds a new xrecord to a dictionary, adds the dictionary to the named object dictionary, and then adds data to the xrecord. The listXrecord() function opens an xrecord, obtains its data list, and sends the list to be printed. For the complete program, see the ObjectARX samples\database\xrecord_dg directory.
void createXrecord() { AcDbDictionary *pNamedobj, *pDict; acdbHostApplicationServices()->workingDatabase() ->getNamedObjectsDictionary(pNamedobj, AcDb::kForWrite); // Check to see if the dictionary we want to create is // already present. If not, then create it and add // it to the named object dictionary. // if (pNamedobj->getAt("ASDK_DICT", (AcDbObject*&) pDict, AcDb::kForWrite) == Acad::eKeyNotFound) { pDict = new AcDbDictionary; AcDbObjectId DictId; pNamedobj->setAt("ASDK_DICT", pDict, DictId); } pNamedobj->close(); // Add a new xrecord to the ASDK_DICT dictionary. // AcDbXrecord *pXrec = new AcDbXrecord; AcDbObjectId xrecObjId; pDict->setAt("XREC1", pXrec, xrecObjId); pDict->close(); // Create a resbuf list to add to the xrecord. // struct resbuf *pHead; ads_point testpt = {1.0, 2.0, 0.0}; pHead = acutBuildList(AcDb::kDxfText, "This is a test Xrecord list", AcDb::kDxfXCoord, testpt, AcDb::kDxfReal, 3.14159, AcDb::kDxfAngle, 3.14159, AcDb::kDxfColor, 1, AcDb::kDxfInt16, 180, 0); // Add the data list to the xrecord. Notice that this // member function takes a reference to resbuf, NOT a // pointer to resbuf, so you must dereference the // pointer before sending it. // pXrec->setFromRbChain(*pHead); acutRelRb(pHead); pXrec->close(); } // Gets the xrecord associated with the key XREC1 and // lists out its contents by passing the resbuf list to the // function printList. // void listXrecord() { AcDbDictionary *pNamedobj; acdbHostApplicationServices()->workingDatabase() ->getNamedObjectsDictionary(pNamedobj, AcDb::kForRead); // Get the dictionary object associated with the key ASDK_DICT. // AcDbDictionary *pDict; pNamedobj->getAt("ASDK_DICT", (AcDbObject*&)pDict, AcDb::kForRead); pNamedobj->close(); // Get the xrecord associated with the key XREC1. // AcDbXrecord *pXrec; pDict->getAt("XREC1", (AcDbObject*&) pXrec, AcDb::kForRead); pDict->close(); struct resbuf *pRbList; pXrec->rbChain(&pRbList); pXrec->close(); printList(pRbList); acutRelRb(pRbList); }