[CONNECT C++] Programatically add ItemTypes/PropertyDefinitions to an Item Library

I've got a large number of pre-CONNECT Xttribute definitions that I want to "convert" into ItemTypes. I started to manually input the data (mainly strings) and decided it would be less error prone if I could programatically insert them instead of manually entering them. In my app, I've got the ECSchemaPtr to the ItemType library that I want to insert the data into, but there must be more required to add an ItemType to a ItemTypeLibrary than just adding in a ECClass. My app creates the new ECClass in the schema, and completes with any (known) errors, However, when I attempt to open the Item Types dialog, CONNECT crashes.

CreateNewClassECN::ECSchemaPtr schemaPtr);
{
	ECObjectsStatus				ecStatus;
	ECClassP				pClass=nullptr;

	// create a new class
	ecStatus = schemaPtr->CreateClass(pClass,L"MyFirstClass");
	printf("CreateClass(), ecStatus=%d\n",ecStatus);
	//
	ecStatus=pClass->SetDescription(L"MyDescription");
	printf("SetDescription(), ecStatus=%d\n",ecStatus);
	ecStatus=pClass->SetDisplayLabel(L"MyDisplayLabel");
	printf("SetDisplayLabel(), ecStatus=%d\n",ecStatus);
}


DgnECManagerR dgnECManager = DgnECManager::GetManager();
SchemaKey				schemaKey(L"DgnCustomItemTypes_SRSFeatureTest",1,0);	// an ItemType library
SchemaInfo schemaToFind (schemaKey, *ISessionMgr::GetActiveDgnFile());
ECN::ECSchemaPtr schemaPtr = dgnECManager.LocateSchemaInDgnFile (schemaToFind, ECN::SCHEMAMATCHTYPE_Latest);

CreateNewClass(schemaPtr );

 

 

 

Bruce

Parents Reply
  • FYI, more generally - you never edit a persistent schema directly.
    You must create a copy of it, apply your modifications, and then use DgnECManager::UpdateSchema() - with the caveat that unless you take care of remapping existing ECInstances to match the new schema, any existing ECInstances will remain unmodified (and potentially unreadable, if e.g. you deleted their ECClass).
    ItemTypeLibrary takes care of all of this for you.

    Answer Verified By: Bruce Reeves SRNS 

Children
No Data