//ElmentHandler eh;(参数化单元)
FindInstancesScopePtr scope = FindInstancesScope::CreateScope(eh, FindInstancesScopeOption(DgnECHostType::All)); ECQueryPtr query = ECQuery::CreateQuery(ECQUERY_PROCESS_SearchAllClasses); DgnECInstanceIterable iterable = Bentley::DgnPlatform::DgnECManager::GetManager().FindInstances(*scope, *query); for (DgnECInstanceIterable::const_iterator it = iterable.begin(); it != iterable.end(); ++it) { DgnECInstancePtr instance = *it; ECN::ECClassCR instanceClass = instance->GetClass(); WString classDisplayName = instanceClass.GetDisplayLabel();
ECPropertyIterable properties = instanceClass.GetProperties(); for (ECPropertyIterable::const_iterator it = properties.begin(); it != properties.end(); ++it) { ECValue v; ECPropertyCP pProp = (*it); if (pProp->GetName().find(L"ParameterValuesContainer")) continue;
ECValue v1;
WCharCP propertyAccessString = pProp->GetName().c_str(); ECObjectsStatus status = instance->GetValue(v1, propertyAccessString, 0); if (ECOBJECTS_STATUS_Success != status) continue;
}
现在我能获取ECValue v1,调试看到其如下形式:
看了下帮助文档没发现读取struct里面的值的函数,希望得到大家的帮助!
您是想在复制参数化单元时修改参数的值吗?这一块底层相当复杂,我给你一个样例供你参考:
private static DgnModel LocateCellModel(string name) { var opts = CellLibraryOptions.Include3d | CellLibraryOptions.IncludeAllLibraries | CellLibraryOptions.IncludeParametric; var libs = new CellLibraryCollection(opts); DgnModel cellModel = null; foreach (var lib in libs) { MessageCenter.Instance.ShowInfoMessage(lib.Name, lib.Name, false); if (name.Equals(lib.Name)) { StatusInt status; cellModel = lib.File.LoadRootModelById(out status, lib.File.FindModelIdByName(lib.Name), true, false, true); break; } } return cellModel; } public static void CreateParametricCell(string pcName) { const string setName = "Standard"; var dgnFile = Session.Instance.GetActiveDgnFile(); var dgnModel = Session.Instance.GetActiveDgnModel(); var pcDef = ParametricCellDefinitionElement.FindByName(pcName, dgnFile); if (null == pcDef) //Not find cell def in active design file { var cellModel = LocateCellModel(pcName); if (null == cellModel) { MessageCenter.Instance.ShowErrorMessage("Not found cell", null, true); return; } var hdlr = DgnComponentDefinitionHandler.GetForModel(cellModel); var status = hdlr.DefinitionModelHandler.CreateCellDefinition(dgnFile); if (ParameterStatus.Success == status) pcDef = ParametricCellDefinitionElement.FindByName(pcName, dgnFile); else { MessageCenter.Instance.ShowErrorMessage("Error Creating cellDef", null, true); return; } } //IECStructArrayValue, IECArrayValue, IECStructValue, IECPropertyValue var pc = ParametricCellElement.Create(pcDef, setName, dgnModel); IDgnECInstance inst = pc.Parameters as IDgnECInstance; IECArrayValue arr = inst.GetPropertyValue("ParameterValuesContainer") as IECArrayValue; IECStructValue structVal = arr[1] as IECStructValue; // .Adhoc_Name = _LOCAL_Cabinet_W structVal.SetValue("Adhoc_Value", 2.0); inst.ScheduleChanges(pc); DTransform3d trans = DTransform3d.Identity; trans.Translation = new DVector3d(1000, 2000, 3000); //UOR unit TransformInfo transInfo = new TransformInfo(trans); pc.ApplyTransform(transInfo); pc.AddToModel(); }
是的 符老师,我看您代码里面有 IECArrayValue 和IECStructValue类,但我在ce的sdk里面没看到有关这些类的定义以及说明,这是未开放的吗?
C++提取一个属性为数组的情况需要通过以下步骤完成:
FindInstancesScopePtr scope = FindInstancesScope::CreateScope((ElementHandleCR)*entry, FindInstancesScopeOption(DgnECHostType::All)); ECQueryPtr query = ECQuery::CreateQuery(ECQUERY_PROCESS_SearchAllClasses); DgnECInstanceIterable iterable = Bentley::DgnPlatform::DgnECManager::GetManager().FindInstances(*scope, *query); int i = 0; for (DgnECInstanceIterable::const_iterator it = iterable.begin(); it != iterable.end(); ++it) { DgnECInstancePtr instance = *it; WString filename; filename.Sprintf(L"D:\\%d.xml", i); instance->WriteToXmlFile(filename.data(), true, true); ECN::ECClassCR instanceClass = instance->GetClass(); WString classDisplayName = instanceClass.GetDisplayLabel(); wprintf(L"%s\n", classDisplayName.data()); ECPropertyIterable properties = instanceClass.GetProperties(); for (ECPropertyIterable::const_iterator it = properties.begin(); it != properties.end(); ++it) { ECValue v; ECPropertyCP pProp = (*it); if (pProp->GetName().Equals(L"ParameterValuesContainer")){ if (pProp->GetIsArray()) { //输出参数化单元参数定义有哪些属性 ArrayECPropertyCP aep = pProp->GetAsArrayProperty(); ECN::ECClassCP _instanceClass = aep->GetStructElementType(); ECPropertyIterable _properties = _instanceClass->GetProperties(false); wprintf(L"ECClass:%s\n", _instanceClass->GetName().data()); for (ECPropertyIterable::const_iterator it1 = _properties.begin(); it1 != _properties.end(); ++it1) { wprintf(L"PropertyName:%s:Type:%s\n", (*it1)->GetName().data(), (*it1)->GetTypeName().data()); } /* 输出信息为: DgnCellParameters PropertyName:Adhoc_Name:Type:string PropertyName:Adhoc_Value:Type:string PropertyName:Adhoc_Label:Type:string PropertyName:Adhoc_Type:Type:int PropertyName:Adhoc_ExtendType:Type:string PropertyName:Adhoc_Unit:Type:string PropertyName:Adhoc_IsReadOnly:Type:boolean PropertyName:Adhoc_IsHidden:Type:boolean PropertyName:Meta_DefinitionScope:Type:boolean PropertyName:Meta_Hidden:Type:boolean 可以看出参数定义信息各个属性的名称和类型,可以看出我们只需要提取Adhoc_Label和Adhoc_Value就可以了 两个属性都是String类型 */ //获取数组个数 instance->GetValue(v, pProp->GetName().data()); ArrayInfo ai = v.GetArrayInfo(); int count = ai.GetCount(); for (int index = 0; index < count; index++) { wprintf(L"---------------index:%d---------------\n", index); instance->GetValue(v, pProp->GetName().data(), index); if (v.IsStruct()) wprintf(L"Struct\n"); IECInstancePtr _intance = v.GetStruct(); for (ECPropertyIterable::const_iterator it1 = _properties.begin(); it1 != _properties.end(); ++it1) { if ((*it1)->GetName().Equals(L"Adhoc_Label") || (*it1)->GetName().Equals(L"Adhoc_Value")) { ECValue _v; _intance->GetValue(_v, (*it1)->GetName().data()); if (_v.IsUtf8()) { Utf8CP _string = _v.GetUtf8CP(); WString string(_string); wprintf(L"PropertyName:%s:Value:%s\n", (*it1)->GetName().data(), string.data()); } else { WCharCP string = _v.GetString(); wprintf(L"PropertyName:%s:Value:%s\n", (*it1)->GetName().data(), string); } } } } } else{ printf("Not Array\n"); } } } i++; }
详细请看注释,结果输出为:
---------------------------------------------------------------
中国市政工程西北设计研究院有限公司武汉分院
Answer Verified By: qh zh
非常感谢!
不客气,原理很简单,只是文档不丰富,需要自己摸索
这个摸索出来还是花了不少时间的,所以很感谢,向你学习!
感谢郑刚出手答复!真正的高手!已加入精华帖:
https://communities.bentley.com/communities/other_communities/bdn_other_communities/w/chinabdn-wiki/36629/page