hi~
I want to get properties by category. Just like the title in the picture below to classify and export. But only the customized ones that I export can not be exported by clicking here. The circles in the picture are uniformly assigned to "BREP cells". How to classify each class?
Here is my code. Thank you very much.
code:
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.DisplayLabel + "]"; 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; var a = propertyValue.Type; if (propertyValue.TryGetStringValue(out strVal)) { LogLine = "\tProperty=" + propertyEnum.Current.DisplayLabel + ", stringValue=" + strVal; WriteLogLine(LogLine); //LogLine = UnicodeToString("u53c2"); //WriteLogLine(LogLine); } else if (propertyValue.TryGetDoubleValue(out dblVal)) { LogLine = "\tProperty=" + propertyEnum.Current.DisplayLabel + ", doubleValue=" + dblVal.ToString(); WriteLogLine(LogLine); } else if (propertyValue.TryGetIntValue(out intVal)) { LogLine = "\tProperty=" + propertyEnum.Current.DisplayLabel + ", intValue=" + intVal.ToString(); WriteLogLine(LogLine); } } }
john siomn said:I want to get properties by category.
It cannot be done in one step.
To write right code, you have to understand how EC schemas work and how EC classes are defined in what structure and using what custom attributes. Without knowing that, it!s hard to design the right approach and to write any code.
What is displayed as "Category" is classification defined using custom attributes, so when you want to do the same split, you have to analyze EC schemas, check every EC property for defined Category attribute and split the properties to the categories in your code.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Well, I mean. How to get the content in the red box separately.
thank you
With regards
Hi John,
john siomn said:How to get the content in the red box separately.
did you try to search the forum for existing discussions about "Categories"? It has been discussed several times already including code snippets, e.g. here. Also, did you study already EC concepts (API, CRUD operations...)?
The whole code is quite simple (collected from some older snippets, so ugly not following clean code best practices):
using (DgnECInstanceCollection collection = DgnECManager.Manager.GetElementProperties(element, ECQueryProcessFlags.SearchAllClasses)) { foreach (IDgnECInstance instance in collection) { foreach (IECPropertyValue property in instance) { string propVal = property.IsNull ? string.Empty : property.StringValue; // Option 1: Receive category id (defaults defined in Bentley.ECObjects.UI.ECPropertyPane.PropertyCategory enum) IECInstance propertyCategory = property.Property.GetCustomAttributes("EditorCustomAttributes", "Category"); int categoryId = null == propertyCategory ? -1 : propertyCategory.GetPropertyValue("Standard").IntValue; // Option 2: Receive category display label using ECPropertyPane string categoryDisplayLabel; int categoryPriority; bool categoryExpand; ECPropertyPane.GetCategoryInformation(out categoryDisplayLabel, out categoryPriority, out categoryExpand, property.Property, property.Property.ClassDefinition); } } }
It contains everything you need to sort properties by categories. The code is just a draft, so there are not null checks, so I guess maybe it will crash when some property, custom attribute or whatever else is not defined.
Answer Verified By: john siomn