Attempting to add an Item to an Element Template. I've got an ECClassP and from that I can get a DgnECInstanceEnablerPtr. I also have the XInstanceContainerP from the Element Template. It looks like you need to create an IECInstancePtr, somehow, from the ECClassP and then use AddInstance() to add that IECInstancePtr to the XInstanceContainer for that Element Template. To finish, it looks like you need to WriteXInstances() on the XInstanceConatiner then call Write() on the ElementTemplate.
I haven't figured out how to get the IECInstancePtr that is needed for XInstanceContainer::AddInstance(). I (think* it has something to do with the DgnEXInstanceEnabler.
Bruce
Not sure if this is the correct way, but here is a solution I've come up with that adds an Item to an Element Template definition, once you have an ElementTemplateNodePtr :
pTemplate = ElementTemplateUtils::FindTemplateNodeByPath (L"MyTestGroup\\MyTestTemplate", *pActiveFile ); XInstanceContainerP pContainer=pTemplate->GetXInstanceContainer(); // get list of ECXAInstances SchemaKey schemaKey(L"DgnCustomItemTypes_MyStuff", 1, 0); SchemaInfo schemaInfo(schemaKey,*pActiveFile); ECSchemaPtr ecSchema=DgnECManager::GetManager().LocateSchemaInDgnFile(schemaInfo,SCHEMAMATCHTYPE_LatestCompatible,false); ECClassP newItem = ecSchema->GetClassP(L"Backfill__x0020__Area"); // note use of __x0020__ for a space if ( newItem ) { // An ECEnabler is the interface between an ECClass and an ECInstance DgnECInstanceEnablerP enabler = DgnECManager::GetManager().ObtainInstanceEnabler(*newItem, *pActiveFile); StandaloneECEnablerR standaloneEnabler = enabler->GetStandaloneECInstanceEnabler (); IECInstancePtr testInst = standaloneEnabler.CreateInstance(); pContainer->AddInstance(testInst); // can be DgnECInstance, IECRelationshipInstance, DgnElementECInstance, or IDgnECRelationshipInstance pContainer->WriteXInstances(pTemplate->GetElementRef(),&pActiveFile->GetDictionaryModel()); pTemplate->Write(); }
Answer Verified By: Bruce Reeves SRNS