Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Overview of Specific Entities

Each specific entity has its own specific and computed properties. So, each class that represents a type of entity also has these properties and methods for getting, setting and computing them.

In the next examples, OdDbEntityEx is the class that represents a specific entity in the OdDb namespace, which provides access to this entity and the ability to manipulate its properties. The OdDbEntityExPtr class is the typified smart pointer to an instance of this entity and is used for storing and passing references to the entity object.

To create an instance of the specific entity, use the createObject() method which is the static pseudo-constructor. For example:


OdDbEntityExPtr pEntity = OdDbEntityEx::createObject();

The pseudo-constructor initializes the properties of a new instance using default values. After creating it, the default properties of the specified database should be applied to the new instance, then a new instance must be added in model space, paper space, or a block using the appendOdDbEntity() method. The database associates the object ID with the entity instance. In the following examples, the pDb variable stores a pointer to the database object. For example:


// Apply the default properties of the specified database to the object.
pEntity->setDatabaseDefaults(pDb);

// Add in the block
OdDbBlockTablePtr pBlocks = pDb->getBlockTableId().safeOpenObject(OdDb::kForRead);
OdDbBlockTableRecordPtr pBlock = pBlocks->getAt(L"BLOCK", OdDb::kForWrite);
OdDbObjectId idEntity = pBlock->appendOdDbEntity(pEntity);

// Add in the model space
OdDbBlockTableRecordPtr pModel = pDb->getModelSpaceId().safeOpenObject(OdDb::kForWrite);
pModel->appendOdDbEntity(pEntity);

// Add in the paper space
dDbBlockTableRecordPtr pPaper = pDb->getPaperSpaceId().safeOpenObject(OdDb::kForWrite);
pPaper->appendOdDbEntity(pEntity);

If specific entities are derived from other another entity, they inherit its common properties. Each entity class is derived from the OdDbEntity class, therefore they also inherit the general properties of entities. A pointer to a specific entity object can be converted to an entity object. For example:


OdDbEntityPtr pOdEntity = pEntity;

To verify an instance of the entity, use the isKindOf() and desc() methods. For example:


// Accurate comparing
if(pOdEntity->isA() == OdDbEntityEx::desc())
  odPrintConsoleString(L"\nEntity is the specific entity");

// Check on belonging
if(pOdEntity->isKindOf(OdDbEntityEx::desc()))
  odPrintConsoleString(L"\nEntity is derived from specific entity");
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.