[c# .net CONNECT] Transform failing on groupedhole and SmartSolid/Surface cell header

im trying to scale all elements within a model about 0,0,0 point.

then i run it, it scales most of the elements. I put a try catch with in the element loop to see what elements it was failing to transform. and it was always either a Grouped Hole element or a Smart Solid/Surface element. all listed as a CellHeader type.  how should i handle transforming these elements? my example code is below.

ModelElementsCollection graphicalElements = curModel.GetGraphicElements();
                            foreach (Bentley.DgnPlatformNET.Elements.Element curElement in graphicalElements)
                            {
                                try
                                {
                                    DTransform3d dTransform3D = DTransform3d.Scale(newScale);
                                    Bentley.DgnPlatformNET.TransformInfo transformInfo = new TransformInfo(dTransform3D);
                                    curElement.ApplyTransform(transformInfo);
                                    curElement.ReplaceInModel(curElement);
                                }
                                catch (Exception e)
                                {
                                    Exception error = e;
                                }
                            }

EDIT: forgot to put what the error is:

Parents
  • Hi John,

    and it was always either a Grouped Hole element or a Smart Solid/Surface element. all listed as a CellHeader type

    In API, neither Groupe Holes nor SmartSolid elements, are not cells!

    Yes, they are stored in DGN file as "special" cell elements, but it's technical detail, because API abstraction understand these objects not as cells (because in underlying native API, every "MicroStation element" has own ElementHandler).

    what elements it was failing to transform.

    I see the same issue with SmartSolid (BrepCellHeaderElement class), but GroupedHole (GroupedHoleElement class) is scaled fine.

    how should i handle transforming these elements?

    I do not know why specifically SmartSolid raises this exception, but you can use this workaround:

    DgnModel model = Session.Instance.GetActiveDgnModel();
    
    ModelElementsCollection elements = model.GetGraphicElements();
    
    DTransform3d scale = DTransform3d.Scale(scaleValue);
    TransformInfo tInfo = new TransformInfo(scale);
    
    foreach (Element element in elements)
    {
        using (Element original = model.FindElementById(element.ElementId))
        {
            element.ApplyTransform(tInfo);
            element.ReplaceInModel(original);
        }
    }

    With regards,

      Jan

    Answer Verified By: John Drsek 

Reply
  • Hi John,

    and it was always either a Grouped Hole element or a Smart Solid/Surface element. all listed as a CellHeader type

    In API, neither Groupe Holes nor SmartSolid elements, are not cells!

    Yes, they are stored in DGN file as "special" cell elements, but it's technical detail, because API abstraction understand these objects not as cells (because in underlying native API, every "MicroStation element" has own ElementHandler).

    what elements it was failing to transform.

    I see the same issue with SmartSolid (BrepCellHeaderElement class), but GroupedHole (GroupedHoleElement class) is scaled fine.

    how should i handle transforming these elements?

    I do not know why specifically SmartSolid raises this exception, but you can use this workaround:

    DgnModel model = Session.Instance.GetActiveDgnModel();
    
    ModelElementsCollection elements = model.GetGraphicElements();
    
    DTransform3d scale = DTransform3d.Scale(scaleValue);
    TransformInfo tInfo = new TransformInfo(scale);
    
    foreach (Element element in elements)
    {
        using (Element original = model.FindElementById(element.ElementId))
        {
            element.ApplyTransform(tInfo);
            element.ReplaceInModel(original);
        }
    }

    With regards,

      Jan

    Answer Verified By: John Drsek 

Children