【MSCE C#】如何获取dgn模型中所有元素的属性?

请问如何获取dgn模型中所有元素的属性呢?目前能够得到所有元素的集合,并能遍历判断这些元素的类型,但不知道如何获取每类元素对应的所有属性。

Parents
  • 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 

Reply Children