如何获取构建所有属性信息

老师们好,我想得到图片里面所有的属性信息。我看了很多帖子都没有实现,只是获得了一点点“通用”属性,比如name color weight之类的。但是其他的属性都没有获取到。

我通过element去便利然后获取IDgnECInstance 再用IECProperty去尝试都无法成功。能告诉我的错误在哪里吗?真的非常感谢。

下面是我的部分代码:

DgnModel dgnModel = Session.Instance.GetActiveDgnModel();
IEnumerator<Element> iEe = dgnModel.GetGraphicElements().GetEnumerator();
iEe.Reset();
while (iEe.MoveNext())
{
Element elTmp = iEe.Current;
LogLine = string.Format("ElementId : {0} ClassType : {1} ElemenType : {2} ElemenTypeName : {3}", elTmp.ElementId.ToString(), elTmp.GetType().ToString(), elTmp.ElementType, elTmp.TypeName);
WriteLogLine(LogLine);

DgnECManager aa = DgnECManager.Manager;
DgnECInstanceCollection ss = aa.GetElementProperties(elTmp, ECQueryProcessFlags.SearchAllClasses);
//DgnECInstanceCollection ss = aa.GetElementProperties(elTmp, ECQueryProcessFlags.);
IEnumerator<IDgnECInstance> ie = ss.GetEnumerator();


ElementPropertiesGetter pgetter = new ElementPropertiesGetter(elTmp);
var color = pgetter.Color;
var ww = pgetter.Weight;

try
{

var clas1s = pgetter.ElementClass.ToString();
var LineStyle = pgetter.LineStyle.ToString();

Bentley.MstnPlatformNET.Session org = Bentley.MstnPlatformNET.Session.Instance;
FileLevelCache lc = org.GetActiveDgnFile().GetLevelCache();
LevelHandle lh = lc.GetLevel(pgetter.Level, false);
string levelname = lh.Name;
//ElementPropertiesGetter v3 = new ElementPropertiesGetter();
//DVector3d v3 = pgetter.Thickness();

LogLine = string.Format("color : {0} ww : {1} name : {2} class : {3} LineStyle : {4}", color, ww, levelname, clas1s, LineStyle);
WriteLogLine(LogLine);

}
catch(ArgumentNullException)
{
LogLine = string.Format("color111 : {0} ww : {1} ", color, ww);
WriteLogLine(LogLine);
}
ie.Reset();
while (ie.MoveNext())
{
IDgnECInstance idec = ie.Current;
IEnumerator<IECPropertyValue> iem = idec.GetEnumerator(false);
if (iem != null)
{
iem.Reset();
while (iem.MoveNext())
{
IECPropertyValue tmpProperty = iem.Current;
tmpProperty.Property.ToString();

foreach (IECProperty prop in idec.ClassDefinition.Properties(true))
{
var nn = prop.Name;
}

}

}
}

Parents
  • BTW Your code looks too complicated, see e.g. this thread for simpler way how to use collection received from GetElementProperties method.

    Can you share your model as an example to check what schemas are used and whether "other properties" comes from intrinsic or extrisnic schemas?

    Another good source of information is this blog about CRUD operations with EC data.

    With regards,

      Jan

  • Thank you very much for your prompt. I got some information according to the example. But the corresponding project name cannot be obtained. How can I get this?

    Thank you very much for your prompt. I got some information according to the example. But the corresponding project name cannot be obtained. How can I get this?

    A and B in the figure. All the A's I've got are some kind of random code like this.

    Chinese is a mess of code. English is normal.

     IEnumerator<Element> iEe = dgnModel.GetGraphicElements().GetEnumerator();
                iEe.Reset();
                while (iEe.MoveNext())
                {
                    Element elTmp = iEe.Current;
                    LogLine = string.Format("ElementId : {0}  ClassType : {1}  ElemenType : {2}  ElemenTypeName : {3}", elTmp.ElementId.ToString(), elTmp.GetType().ToString(), elTmp.ElementType, elTmp.TypeName);
                    WriteLogLine(LogLine);
                    Element myElem = dgnModel.FindElementById((ElementId)elTmp.ElementId);
                    if(myElem ==null)
                    {
                        
                    }
                    DgnECManager ecManager = DgnECManager.Manager;
                    int count = 0;
                    DgnECInstanceCollection instCol = ecManager.GetElementProperties(myElem, ECQueryProcessFlags.SearchAllClasses);
                    foreach (IDgnECInstance inst in instCol)
                    {
                        count++;
                        
                        LogLine = "----ECInstance" + count.ToString() + "[" + inst.ClassDefinition.Name + "]";
                        WriteLogLine(LogLine);
                        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))
                            {
                                LogLine = "\tProperty=" + propertyEnum.Current.Name + ", Value=" + strVal;
                                WriteLogLine(LogLine);
                            }
                            else if (propertyValue.TryGetDoubleValue(out dblVal))
                            {
                                LogLine = "\tProperty=" + propertyEnum.Current.Name + ", Value=" + dblVal.ToString();
                                WriteLogLine(LogLine);
                            }
    
                            else if (propertyValue.TryGetIntValue(out intVal))
                            {
                                LogLine = "\tProperty=" + propertyEnum.Current.Name + ", Value=" + intVal.ToString();
                                WriteLogLine(LogLine);
                            }
                                
                        }
                    }

    thankyou

  • I found that the Chinese characters are processed Unicode encoded characters.

    But I still don't know how to get the information of B in the picture.

Reply Children