Issue:
How can I insert a multiple view block instance (AecDbMvBlockRef) with associated attributes using OMF? For example, I'd like to insert a column grid tag and provide a tag number to it.
Solution:
A multiple view block instance (AecDbMvBlockRef) is a display reference to one of the multiple view block definitions (AecDbMvBlockDef) which are stored in the dictionary AecDictMvBlockDef. AecDbMvBlockDef contains many view blocks (AecMvBlockView) which are used by individual display representations for different view directions. Each view block instance (AecMvBlockViewInstance) can contain many multiple view attributes (AecMvBlockAttribute) which are just wrappers of AutoCAD attribute objects (AcDbAttribute).
The appended code demonstrates how to achieve the desired task. This can be easily applied to other multiple block definitions. When you do so, please make sure that the name of multiple view block definition is provided correctly, the number of attributes is checked, proper attribute tags are retrieved from the view block definition, and the attributes and multiple view block reference are updated.
// get a multi view block definition.
// for example, "StandardGridBubble". (We assume we have it defined.)
//
AecRmCString mvName = "StandardGridBubble";
AcDbObjectId mvBlkDefId;
AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
AecDictMvBlockDef mvDict(pDb);
if( mvDict.isValid() != Adesk::kTrue )
return;
if( mvDict.has(mvName) )
mvDict.getAt(mvName, mvBlkDefId);
else
return;
// create a multi view block reference.
//
AecDbMvBlockRef* mvBlkRef = new AecDbMvBlockRef;
assert(mvBlkRef != NULL);
mvBlkRef->subSetDatabaseDefaults( pDb );
mvBlkRef->setToStandard( pDb );
mvBlkRef->setBlockDefId(mvBlkDefId);
mvBlkRef->setLocation(AcGePoint3d(0,0,0));
mvBlkRef->setRotation(0);
AcGeScale3d scale3d(350);
mvBlkRef->setScale(scale3d);
// set the attributes.
if( mvBlkRef->hasAttributes() )
{
// Here we choose the first view instance for the simplicity.
//
AecMvBlockViewInstance* blkViewIns = mvBlkRef->getViewBlockAt(0);
assert(blkViewIns != NULL);
// set the "Label" attribute to "A0".
int indexFoundAt;
if( blkViewIns->findAttribute(_DNT("LABEL"), indexFoundAt)==Adesk::kTrue )
{
AecMvBlockAttribute *mvBlkAtt;
AcDbAttribute *acadAtt;
mvBlkAtt = blkViewIns->getAttributeAt(indexFoundAt);
assert(mvBlkAtt != NULL);
acadAtt = mvBlkAtt->attributeForWrite( );
assert(acadAtt != NULL);
acadAtt->setTextString(_DNT("A0"));
acadAtt->close();
mvBlkAtt->setNeedsUpdate(Adesk::kTrue);
}
}
mvBlkRef->updateViewBlocks();
Aec::transformToWcs(mvBlkRef, pDb);
Aec::addToCurrentSpaceAndClose(mvBlkRef);