I have a dimension in a dynamic block. When I modify the parameter programmatically, the block gets updated but the dimension does not update itself. What can I do to resove this ?
When the parameter is modified, AutoCAD creates a new anonymous block. To ensure that the dimension also get updated to reflect the change in the parameter, this anonymous block must be opened for write and marked as "modified". This will ensure that AutoCAD updates the dimension.
Here is the sample code. The complete sample project can be downloaded from the link below.
AcDbObjectId selectedObjectId = _blockRefOid;
AcArray<AcDbObjectId> oidArray;
AcDbBlockReference *pBlockRef = NULL;
acdbOpenObject(pBlockRef, selectedObjectId, AcDb::kForWrite);
AcDbBlockTableRecord *pBlockTableRecord1 = 0;
acdbOpenObject(
pBlockTableRecord1,
pBlockRef->blockTableRecord(),
AcDb::kForWrite
);
ACHAR *name = NULL;
pBlockTableRecord1->getName(name);
AcDbBlockTableRecordIterator *pIterator = NULL;
pBlockTableRecord1->newIterator(pIterator);
while(pIterator->done() == false)
{
AcDbEntity *pEnt1 = NULL;
pIterator->getEntity(pEnt1, AcDb::kForWrite);
if (pEnt1->isKindOf(AcDbBlockReference::desc()))
{
oidArray.append(pEnt1->objectId());
}
pEnt1->assertWriteEnabled();
pEnt1->recordGraphicsModified(true);
pEnt1->close();
pIterator->step();
}
delete pIterator;
pBlockTableRecord1->close();