In the database, all entities are owned by blocks (compositions of geometrical objects that have a name and are processed as a single whole) which are stored in the block table as block table records. The parent object for any entity is a block, for example, the Model Space block. Each type of entity is represented by the specific class that contains a set of entity parameters and methods for creating and modifying the entity. For example, the OdDbCircle class represents a circle entity.
The OdDbBlockTable and OdDbBlockTableRecord classes represent the block table and block table records accordingly. For more information about blocks, see Entities and Blocks and Overview of Blocks.
The following example demonstrates how to create database entities; the example creates a circle and a line inside model space and sets parameters for each.
/**********************************************************************/
/* Open the Block Table */
/**********************************************************************/
OdDbBlockTablePtr pTable = pDb->getBlockTableId().safeOpenObject(OdDb::kForWrite);
/**********************************************************************/
/* Open the Model Space block */
/**********************************************************************/
OdDbBlockTableRecordPtr pModelSpace = pDb->getModelSpaceId().safeOpenObject(OdDb::kForWrite);
/*************************************************************************************/
/* Create a Circle object, put it to Model Space and set the center point and radius */
/*************************************************************************************/
OdDbCirclePtr pCircle = OdDbCircle::createObject();
pModelSpace->appendOdDbEntity(pCircle);
OdGePoint3d center = OdGePoint3d(2.0,0,0);
pCircle->setCenter(center);
pCircle->setRadius(2.0);
/**********************************************************************************************/
/* Create a Line object, put it to Model Space and set the start and end points and the color */
/**********************************************************************************************/
OdDbLinePtr pLine = OdDbLine::createObject();
pModelSpace->appendOdDbEntity(pLine);
pLine->setStartPoint(OdGePoint3d(2,0,0));
pLine->setEndPoint(OdGePoint3d(4,2,0));
pLine->setColorIndex(12);