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.
To attach an entity to an associative dimension:
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);
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);
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).
Working with Associative Dimensions
Associative Dimensions Architecture
Recalculation of Associative Dimensions Implementation
Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.
|