请问如何获取dgn模型中所有元素的属性呢?目前能够得到所有元素的集合,并能遍历判断这些元素的类型,但不知道如何获取每类元素对应的所有属性。
public static void GetProperties(string unparsed) { ulong id; try { id = ulong.Parse(unparsed); } catch { CommonClass.ShowMessage("未提供ElemId作为命令参数或提供的参数不合法"); return; } DgnFile dgnFile = Session.Instance.GetActiveDgnFile(); DgnModel dgnModel = Session.Instance.GetActiveDgnModel(); Element myElem = dgnModel.FindElementById((ElementId)id); if (null == myElem) { CommonClass.ShowMessage("所提供ElemId无效"); return; } DgnECManager ecManager = DgnECManager.Manager; int count = 0; DgnECInstanceCollection instCol = ecManager.GetElementProperties(myElem, ECQueryProcessFlags.SearchAllClasses); foreach (IDgnECInstance inst in instCol) { count++; CommonClass.ShowMessage("----ECInstance" + count.ToString() + "[" + inst.ClassDefinition.Name + "]"); IEnumerator<IECProperty> propertyEnum = inst.ClassDefinition.GetEnumerator(); while (propertyEnum.MoveNext()) { IECPropertyValue propertyValue = inst.GetPropertyValue(propertyEnum.Current.Name); if (propertyValue.IsArray) { IECArrayValue arrayVal = propertyValue as IECArrayValue; if (arrayVal.Count >= 1) propertyValue = arrayVal[0]; } string strVal; double dblVal; int intVal; if (propertyValue.TryGetStringValue(out strVal)) CommonClass.ShowMessage("\tProperty=" + propertyEnum.Current.Name + ", Value=" + strVal); else if (propertyValue.TryGetDoubleValue(out dblVal)) CommonClass.ShowMessage("\tProperty=" + propertyEnum.Current.Name + ", Value=" + dblVal.ToString()); else if (propertyValue.TryGetIntValue(out intVal)) CommonClass.ShowMessage("\tProperty=" + propertyEnum.Current.Name + ", Value=" + intVal.ToString()); } } }
谢谢您老师,学习了一下,帮助非常大
这些是全新的EC编程,也是比较难的一部分。如果确认正确的话,麻烦点击正确答案帖子下的Verify Answer来结贴。
Answer Verified By: Leon Cheng
符老师,想问一下,这个是不是只能获取MicroStation软件中能够看到的元素属性呀,有些在软件中看不到的属性是不是获取不到呢?
可以获取到,只要是在Properties窗口中能够看到的属性基本上都是通过EC机制存储的。
也就是说EC机制只能获取属性窗口中的属性了是吗?那其他没有在属性窗口中显示的属性通过哪种方式获取呢?
您说的属性具体指哪种属性?
比如有一个桥梁,要获取某段梁的起始编号,梁宽度,长度,自重等一些信息呢?这是都不在属性窗口的基本信息里面