Issue:
Using the command _AecPropertyDataEdit and Add button, we can add a property set to an AEC object. How can I do this programmatically in OMF?
Solution:
The property set object is added to AEC object's extension dictionary named "AEC_PROPERTY_SETS". Its name will be anonymous (starting with "*"). In order to create it correctly, a property set definition must be referenced, as in the UI. The latter is stored in the dictionary "AEC_PROPERTY_SET_DEFS" under AutoCAD Named Object Dictionary). The following code shows exactly how to do it.
// get working database
Acad::ErrorStatus es;
AcDbDatabase *pCurDb = acdbHostApplicationServices()->workingDatabase();
if(pCurDb == NULL)
return;
// get a property set definition name, e.g. Door, Frame, etc.
AecUiPrString promptStr(_T("Input property set definition name"), Adesk::kFalse);
if(promptStr.go() != AecUiPr::kOk)
return;
// get dictionary of property set definition
AecDictPropertySetDef dictPropSet(pCurDb);
if( !dictPropSet.isValid() )
{
acutPrintf(_T("\nCan not find any property set definitions."));
return;
}
// get the specific PropSetDef Id
AcDbObjectId objId;
es = dictPropSet.getAt(promptStr.value(), objId);
if( es != Acad::eOk )
{
acutPrintf(_T("\nThe %s property set does not exist."),
promptStr.value());
return;
}
// select a door
AecUiPrEntity promptEnt(_T("Select an Door"), NULL);
promptEnt.addAllowedClass(AecDbDoor::desc());
if(promptEnt.go() != AecUiPr::kOk)
{
acutPrintf(_T("\nI am only able to work on AEC entities. :-("));
return;
}
// open the door for write
AecDbDoor *pEnt;
es = AecDbDoor::open(pEnt, promptEnt.objectId(), AcDb::kForWrite);
if(es != Acad::eOk)
{
acutPrintf(_T("\nCan not open this AEC entities to write."));
return;
}
// add property set to door
es = AecDbPropertySet::addPropertySet(pEnt, objId);
if(es != Acad::eOk)
{
acutPrintf(_T("\nCan not add property set."));
return;
}
pEnt->close();