[CONNECT .net c#] How to copy ECInstance from cell to all its subelements

need a little bit of direction/help. I have a dgn file with 10000s of elements that came from different shape files. to be clear these are elements in the model. It is not a shape file reference. 

the attributes from the shape file turned into an item on the element. 

my problem is the shape file did some weird things when importing it. some of the linear line strings came in as a cell comprised of several line strings. i need to drop those cells but i don't want to lose the attribute data that came from the shape file.

So i want to get the item on the cell and then loop the sub elements and apply that item to all the sub elements.

finding the cells and looping the sub-elements is not a problem, its how to copy the item.

i normally deal with item types but quickly found out these items are not an item type and i cant use the sdk calls im used it using.

im able to see the item on a given cell by looping the ECInstances.

but im struggling with the next step. 

im thinking i need to get the schema for this item and then attach it as a new ECInstance to each sub-element and then apply the property values from the item on the cell to each new ec instance on each sub-element.

if i was dealing with item types i would create a customitemhost and applycustomitem. but not sure how do to this at at the ec level???

using (DgnECInstanceCollection dgnECInstances = DgnECManager.Manager.GetElementProperties(el, ECQueryProcessFlags.SearchAllClasses))
                    foreach (IDgnECInstance ecInstance in dgnECInstances)
                        if (ecInstance.ClassDefinition.Name == "OhioRailLinesSelect")
                            //get schema from instance
                            IECSchema schema = ecInstance.ClassDefinition.Schema;
                            ChildElementCollection subElements = (el as CellHeaderElement).GetChildren();
                            foreach (Element subElement in subElements)
                                //add new EC instance to subelement??

                                //loop and apply value to each property 

any help/direction would be great! thanks

Parents Reply
  • Hi John,

    but its only for the current session of microstation. once i close and reopen the sub elements no longer have the item attached. 

    I am not sure. You can try to rewrite the instance, and when it does not help, it can be caused by API itself.

    Or, of course, it can be cause by the model itself, but I do not expect the problem is here. Is it possible to share an example, just with a few cells (with EC data attached)?

    with getting the IEnumerable<string> propertyAccessors.

    I do not understand why you use this method.

    CopyInstance takes one EC instance and copy all data to another EC instance of the same EC class. I do not see any reason to use accessors and other features.

    but im doing something wrong because it just crashes microstation.

    I would write the code in a different way. I do not know why you do not enumerate cells in normal way. To use EC approach does not bring any advantage in my opinion in the discussed situation. It would probably lead to different code.

    With regards,