各位老师好,添加一个新埋件,使用ApplyCustomItem 函数第一次写埋件属性可以成功,但第二次选中该埋件进行修改属性时不成功,在CustomItemHost itemHost(eeh, true); // true = schedule changedDgnECInstancePtr pInstance = itemHost.ApplyCustomItem(*itemType);时pInstance 为空,查看eeh正常,请问是什么原因呢,以下为函数部分代码。请老师指点。
void SetElemGraphItemTypeValue(EditElementHandle& eeh, string Solidname, string Solidtype, WString libName, WString typeName, DgnModelRefP model) { WString WSolidname(Solidname.c_str()); WString WSolidtype(Solidtype.c_str()); //ElementRefP oldref = eeh.GetElementRef(); DgnFileP dgnfile = model->GetDgnFileP(); ItemTypeLibraryPtr itemTypeLibrary = ItemTypeLibrary::FindByName(libName.c_str(), *dgnfile); if (itemTypeLibrary == NULL) { itemTypeLibrary = ItemTypeLibrary::Create(libName.c_str(), *dgnfile); } ItemTypeP itemType = itemTypeLibrary->GetItemTypeByName(typeName.GetWCharCP()); if (itemType == NULL) { itemType = itemTypeLibrary->AddItemType(typeName.GetWCharCP()); } WString strName; strName = L"Name"; CustomPropertyP Custype2 = itemType->GetPropertyByName(strName.GetWCharCP()); if (Custype2 == NULL) { Custype2 = itemType->AddProperty(strName.GetWCharCP()); Custype2->SetType(CustomProperty::Type::String); } strName = L"Type"; CustomPropertyP Custype3 = itemType->GetPropertyByName(strName.GetWCharCP()); if (Custype3 == NULL) { Custype3 = itemType->AddProperty(strName.GetWCharCP()); Custype3->SetType(CustomProperty::Type::String); } itemTypeLibrary->Write(); CustomItemHost itemHost(eeh, true); // true = schedule changed DgnECInstancePtr pInstance = itemHost.ApplyCustomItem(*itemType); if (pInstance == nullptr) { return; } ... }