[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
  • Hi John,

    some of the linear line strings came in as a cell comprised of several line strings.

    It's probably done to maintain features collection, which is standard GIS functionality ... and often is translated to MicroStation as "group elements to a cell" ;-)

    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.

    A question is whether to:

    • attach EC data to elements inside cell and to drop it afterwards
    • read EC data from the cell, remember it, drop the cell and to attach data to result

    The first way is of course simpler, but there are some limitations in current NET API (it is not possible to modify a cell content), but I assume it does not apply to EC instance attachment (because it does not modify the element itself).

    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.

    Yes, SHP import creates (from V8i era, when Item Types did not exist) normal EC data.

    but im struggling with the next step. 

    Did you read EC CRUD Operations blog? All tasks are described there, as well as in several examples, delivered with MicroStation SDK.

    and then apply the property values from the item on the cell to each new ec instance on each sub-element.

    The looping EC property, as mentioned in your code snippet, is wrong idea. Technically correct, but useless (and leads to plenty of extra code). There is ECInstanceHelper class available, allowing to copy instance data at once.

    Regards,

      Jan

    Answer Verified By: John Drsek 

Reply
  • Hi John,

    some of the linear line strings came in as a cell comprised of several line strings.

    It's probably done to maintain features collection, which is standard GIS functionality ... and often is translated to MicroStation as "group elements to a cell" ;-)

    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.

    A question is whether to:

    • attach EC data to elements inside cell and to drop it afterwards
    • read EC data from the cell, remember it, drop the cell and to attach data to result

    The first way is of course simpler, but there are some limitations in current NET API (it is not possible to modify a cell content), but I assume it does not apply to EC instance attachment (because it does not modify the element itself).

    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.

    Yes, SHP import creates (from V8i era, when Item Types did not exist) normal EC data.

    but im struggling with the next step. 

    Did you read EC CRUD Operations blog? All tasks are described there, as well as in several examples, delivered with MicroStation SDK.

    and then apply the property values from the item on the cell to each new ec instance on each sub-element.

    The looping EC property, as mentioned in your code snippet, is wrong idea. Technically correct, but useless (and leads to plenty of extra code). There is ECInstanceHelper class available, allowing to copy instance data at once.

    Regards,

      Jan

    Answer Verified By: John Drsek 

Children