Issue:
We would like to create a new Multi-View Block definition. Our program will fill in Name and Description and will need to create "General", "Model", "Plan 1-100", "Plan 1-50" and "Reflected" on Display Representation list box. For "General" and "Model", they will have view block names in View Blocks list box with View Directions assigned. Just like one can do in 'Multi-View Block Definition Properties' dialog box. Please provide some sample.
Solution:
A sample code below demonstrates how to create a MultiView block definition from OMF. This sample adds a new MultiViewBlock definition named "myMvBlockDefOMF". It assumes that a block definition named "myBlock" exists. Please make one beforehand. (Just a circle would do.) This sample adds only one AecMvBlockDispRepDef, but you can add more as you need. Same for AecMvBlockViewDefinition. Try changing the value in the code below and compare them in UI. You will see the correspondence between UI and OMF code.
AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();
Acad::ErrorStatus es;
// hard coding the name of MvBlock definition for simplicity.
AecRmCString sMvBlockDefName=_T("myMvBlockDefOMF");
// get the MvBlock Def dictionary.
AecDictMvBlockDef dictMvBlockDef(pDb);
if(!dictMvBlockDef.isValid()){
acutPrintf(_T("failed to get the MultiBlock definition dictionary!\n"));
return ;
}
// add a record to the dictionary.
AecDbMvBlockDef *pMvBlockDef = AecDbMvBlockDef::cast(dictMvBlockDef.newEntry());
if(pMvBlockDef == NULL) {
acutPrintf(_T("failed to create a new MvBlockDef dictionary record.\n"));
return;
}
es = dictMvBlockDef.addNewRecord(sMvBlockDefName, pMvBlockDef);
if(es != Acad::eOk){
acutPrintf(_T("failed to add a new MvBlockDef \"%s\" \n"), sMvBlockDefName.c_str());
delete pMvBlockDef;
return;
}
// Now, we need to fill in MvBlockDef.
//
// fill in the description
pMvBlockDef->setDescription(_T("This is MvBlock Definition added from OMF."));
// create a new MvBlock's DispRepDef.
// you can create more than one if you want.
AecMvBlockDispRepDef* pMvBlockDispRepDef = new AecMvBlockDispRepDef;
// get a list of disp rep works with MvBlock.
AecDispRepMgr *pDRM = AecBaseServices::service()->dispRepMgr(pDb);
AcDbObjectIdArray ids;
pDRM->getAllViewsFor(AecDbMvBlockRef::desc(), ids);
// for the simplicity we will use the first rep only.
if(ids.length()>0) pMvBlockDispRepDef->setDisplayRep(ids[0]);
AecMvBlockViewDefinition *pMvBlockViewDef = new AecMvBlockViewDefinition;
AcDbObjectId blockObjId;
es = Aec::getBlockTableRecordId(_T("myBlock"), pDb, blockObjId); // we assume we have it defined.
pMvBlockViewDef->setBlockId(blockObjId);
pMvBlockViewDef->setViewOn(Aec::ViewDirection::kViewDirTop, Adesk::kTrue);
pMvBlockViewDef->setViewOn(Aec::ViewDirection::kViewDirBottom, Adesk::kTrue);
es = pMvBlockDispRepDef->addViewBlock(pMvBlockViewDef);
es = pMvBlockDef->addDispRepDef(pMvBlockDispRepDef);
// finishing up.
es = pMvBlockDef->close();
// We have a new MultiBlock definition now.
acutPrintf(_T("\nA new MultiBlock definiton \"%s\" is created. \n"), sMvBlockDefName.c_str());