Issue:
I want to add an anchor onto AecDbMvBlockRef in order to programmatically make it a schedule tag for another ACA object. How can I do that in OMF?
Solution:
We can use AecDbAnchorTagToEnt to do the intended task. The following sample code inserts a metric window tag and anchors it to a window. This sample uses "M_Aec6_Window_Tag" multi view block definition. If it hasn't been imported yet, please drag and drop it from the Design Center before you run the sample.
Note that with this sample, the number in the tag will not be filled automatically. You need to add a property set to the window beforehand to have the tag retrieve the value. You can add a window property set manually. If you want to use OMF, please refer to a blog post Adding a property set programmatically using OMF.
Acad::ErrorStatus es;
// We use a multi view block definition M_Aec3_Window_Tag here.
// (If it hasn't been imported yet, please drag and drop it
// from Design Center.)
AecRmCString mvName = _T("M_Aec6_Window_Tag");
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;
AecDbMvBlockRef* mvBlkRef = new AecDbMvBlockRef;
AEC_ASSERT(mvBlkRef != NULL);
mvBlkRef->subSetDatabaseDefaults( pDb );
mvBlkRef->setToStandard( pDb );
mvBlkRef->setBlockDefId(mvBlkDefId);
// Set the tag location as picked by the user
ads_point pt1;
acedGetPoint(NULL,_T("\nInsertion point: "), pt1);
mvBlkRef->setLocation(AcGePoint3d(pt1[0], pt1[1], pt1[2]));
// Here, we hard code the rotation and scale factor for simplicity.
// It should work well on Metric template.
mvBlkRef->setRotation(0);
AcGeScale3d scale3d(350);
mvBlkRef->setScale(scale3d);
AecDbAnchorTagToEnt* pAnchor = new AecDbAnchorTagToEnt();
// Select a window to anchor the tag to.
AcDbObjectId winId;
AecUiPrEntity promptEnt(_T("Select a window"), NULL);
promptEnt.addAllowedClass(AecDbWindow::desc());
if(promptEnt.go() != AecUiPr::kOk)
{
acutPrintf(_T("\nNot a window."));
return;
}
pAnchor->appendReferenceObject( promptEnt.objectId(), AecObjReferenceInfo::kOwnedBy );
// Set the anchor to the tag.
es = mvBlkRef->setAnchor( pAnchor );
AEC_ASSERT( Acad::eOk == es );
pAnchor->close();
Aec::transformToWcs(mvBlkRef, pDb);
Aec::addToCurrentSpaceAndClose(mvBlkRef);