The database object and its objects have specific methods that return an ID of the required object. In the examples below, the pHost variable stores a pointer to the host application object and the pDb variable stores a pointer to the database object.
OdDbDabasePtr pDb = pHost->createDatabase(); // Db = 3c9b8
To get an ID of an existing object with a handle, use the getOdDbObjectId() method of the database object; it requires a handle of the object and returns the ID associated with this object. For example:
OdDbHandle handle = 0x1F;
OdDbObjectId id = pDb->getOdDbObjectId(handle);
odPrintConsoleString(L"\nHandle = %llx, Db = %lx, Obj = %lx", id.getHandle(), id.database(), id.openObject());
// Handle = 1f, Db = 3c9b8, Obj = 6a5b2
To add an object in a database and associate an ID with it, use the addOdDbObject() method of the database object; it requires a pointer to the object and returns the ID associated with this object as a result of the addition. The object gets the next free handle. For example:
OdDbColorPtr pColor = OdDbColor::createObject();
OdDbObjectId idColor = pDb->addOdDbObject(pColor);
odPrintConsoleString(L"\nHandle = %llx, Db = %lx, Obj = %lx", idColor.getHandle(), idColor.database(), idColor.openObject());
// Handle = 3E, Db = 3c9b8, Obj = 4c1d3
To get an ID of an existing object that has a pointer, use the objectId() method of the object; it does not have arguments and returns the ID associated with this object. For example:
OdDbObjectId idSelf = pColor->objectId();
odPrintConsoleString(L"\nHandle = %llx, Db = %lx, Obj = %lx", idSelf.getHandle(), idSelf.database(), idSelf.openObject());
// Handle = 3E, Db = 3c9b8, Obj = 4c1d3
To get an ID of the owner object, use the ownerId() method of the object; it does not have arguments and returns the ID associated with its owner. For example:
OdDbObjectId idOwner = pColor->ownerId();
odPrintConsoleString(L"\nHandle = %llx, Db = %lx, Obj = %lx", idOwner.getHandle(), idOwner.database(), idOwner.openObject());
// Handle = 1A, Db = 3c9b8, Obj = 4c2e1
To get an ID of the predefined object of a database, use the specific method of the database object using the ID associated with the predefined object. For example, to get the standard text style of a drawing, use the following specific method:
OdDbObjectId idTS = pDb->getTextStyleStandardId();
odPrintConsoleString(L"\nHandle = %llx, Db = %lx, Obj = %lx", idTS.getHandle(), idTS.database(), idTS.openObject());
// Handle = 17, Db = 3c9b8, Obj = 6a5d8
To get the handle of an existing object that has a pointer, use the handle() method of the object; it does not have arguments and returns the handle associated with this object. For example:
OdDbHandle hSelf = pColor->handle();
odPrintConsoleString(L"\nHandle = %llx", hSelf); // Handle = 3E
To get the resident handle, use the getDbHandle() method of the object; it does not have arguments and returns its resident handle. For example:
OdDbHandle hResident = pColor->getDbHandle();
odPrintConsoleString(L"\nHandle = %llx", hResident);
Identifying the Objects of Databases
Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.
|