Drawings SDK Developer Guide > Working with .dwg Files > Working with Entities > Working with Specific Entitites > Working with Dimensions > Working with Associative Dimensions > Creating Associative Dimensions
Creating Associative Dimensions

Associating an OdDbDimAssoc class instance with a dimension


OdDbBlockTableRecordPtr bBTR = btrId.safeOpenObject(OdDb::kForWrite); 
...
OdDbRotatedDimensionPtr pDimension = OdDbRotatedDimension::createObject(); 
pDimension->setDatabaseDefaults(pDb); 
OdDbObjectId dimensionId = bBTR->appendOdDbEntity(pDimension); 
...
OdDbDimAssocPtr pDimAssoc = OdDbDimAssoc::createObject(); 
OdDbObjectId dimAssId; 
OdResult res = pDimAssoc->post(dimensionId, dimAssId); 
pDimAssoc->setRotatedDimType(OdDbDimAssoc::kUnknown);

In the preceding code example, an instance of the OdDbRotatedDimension class is created and added to the database by calling the append OdDbEntity() method of the Block Table Record (BTR). The BTR was created earlier by calling the safeOpenObject() method of the OdDbObjectId object (btrId), passed as an input parameter.

Next, call the post() method of the OdDbDimAssoc class, passing a dimension object ID and a reference to the OdDbDimAssoc object ID.

Then, specify the type of rotated dimension by calling the setRotateDimType() method.

Attaching an entity to an associative dimension

To attach an entity to an associative dimension:

  1. Create one or several snap point references.
  2. Define the type for each created snap point reference.
  3. Add the entity's Id as a main entity object Id for snap point references.
  4. Set the subentity's type for the snap point references.
  5. Set the created snap point references to the OdDbDimAssoc object.

OdDbOsnapPointRefPtr pointRef = OdDbOsnapPointRef::createObject(); 
pointRef->setPoint(pLine->startPoint()); 
pointRef->setOsnapType(OdDb::kOsModeStart); 
pointRef->setNearPointParam(0.0); 
pointRef->mainEntity().objectIds().append(lineId); 
pointRef->mainEntity().subentId().setType(OdDb::kVertexSubentType); 
pDimAssoc->setPointRef(OdDbDimAssoc::kXline1Point, pointRef);  
pointRef = OdDbOsnapPointRef::createObject(); 
pointRef->setPoint(pLine->endPoint()); 
pointRef->setOsnapType(OdDb::kOsModeEnd); 
pointRef->setNearPointParam(1.0); 
pointRef->mainEntity().objectIds().append(lineId); 
pointRef->mainEntity().subentId().setType(OdDb::kEdgeSubentType); 
pDimAssoc->setPointRef(OdDbDimAssoc::kXline2Point, pointRef); 

Implementing the associativity reaction

To make associativity work, add the OdDbDimAssoc object as a reactor for the associated entity by calling the addPersistentReactor() method of the entity. The following is sample code for adding an associative dimension (with Id value passed with dimAssId variable) as a reactor for a Line entity (pLine):

pLine->addPersistentReactor(dimAssId);

Associative dimensions example application

An application containing code samples for creating, associating, and using associative dimensions is located here: {RootDir}\Drawing\Examples\OdWriteEx, where {RootDir} is the ODA installation folder (for example, C:\ODA).

See Also

Working with Associative Dimensions

Associative Dimensions Architecture

Recalculation of Associative Dimensions Implementation

Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.