Issue:
How to add a property definition to a property set definition using OMF?
Solution:
You can access to a property set definition stored in the dictionary "AEC_PROPERTY_SET_DEFS" under AutoCAD Named Object Dictionary) and add a property definition. The following code shows how to do it. This code finds property sets attached to a door and finds definitions. Please set a least one door property set to the door before testing the code. The code adds a property definition “Area” and then sets the value of 15.98.
// get working database
AcDbDatabase *pCurDb = acdbHostApplicationServices()->workingDatabase();
if(pCurDb == NULL)
return;
// select a door
AecUiPrEntity promptEnt(_T("Select a door"), NULL);
promptEnt.addAllowedClass(AecDbDoor::desc());
if(promptEnt.go() != AecUiPr::kOk)
{
acutPrintf(_T("\nAborting command..."));
return;
}
// open the door for read
Acad::ErrorStatus es;
AecDbDoor *pEnt;
es = AecDbDoor::open(pEnt, promptEnt.objectId(), AcDb::kForRead);
if(es != Acad::eOk)
{
acutPrintf(_T("\nCan not open the Door entity."));
return;
}
AcDbObjectId propSetDefId, propSetId;
AecDbPropertySet* propSet;
Adesk::UInt32 propId;
// get property sets from extension dictionary of the selected door
AcDbObjectIdArray propSetIds;
es = AecDbPropertySet::getPropertySets( (AcDbObject*) pEnt, propSetIds);
if(es != Acad::eOk)
{
acutPrintf(_T("\nThere are no property sets in this AEC entity."));
pEnt->close();
return;
}
pEnt->close();
// iterate through all the property sets
for(int iPropSet=0; iPropSet < propSetIds.length(); iPropSet++) {
// get property set object
AecDbPropertySet *propSet = NULL;
AecDbPropertySet::open( propSet, propSetIds[iPropSet], AcDb::kForRead);
AcDbObjectId propSetDefId = propSet->propertySetDef();
propSet->close();
AecDbPropertySetDef* propSetDef;
es = AecDbPropertySetDef::open(propSetDef, propSetDefId, AcDb::kForWrite);
// Add a propertydef to propertyset def
// Create property
AecPropertyDef* pdefArea = new AecPropertyDef;
pdefArea->subSetDatabaseDefaults ( pCurDb) ;
es = pdefArea->setName(_T("Area"));
es = pdefArea->setAutomatic (false);
es = pdefArea->setDataType (AecPropertyDef::kReal );
// Add to Property Set
es = propSetDef->addPropertyDef(pdefArea);
propSetDef->close();
// Open again to make modifications
es = AecDbPropertySet::open(propSet, propSetIds[iPropSet], AcDb::kForWrite);
es = propSet->propertyNameToId(_T("Area"), propId);
es = propSet->setAt(propId, 15.98);
propSet->close();
}