[MSCE 10.17 C#] Detect if element is a sub-element of a cell

I'm working on an application where I'm scanning for elements that have custom ItemTypes applied. I'm using the FindInstancesScopeOption.SearchPublicChildren option to find all instances that match the search. This will find sub-elements of a cell if those sub-element has a custom itemtype attached.

If the found element is a sub-element of a cell, I need to do some special processing to get some properties of the parent cell itself.

I was planning to use the Bentley.DgnPlatformNET.Elements.Element.ParentElement property to determine if the element has a parent, then check if the parent element is a Cell for my special processing.

Is this a viable method or is there a better more direct way to do this?

Parents
  • I wrote code to delete sub-element of a cell. This is part of it. Maybe you find something usfull there

                  try
                   {
                       CellHeaderElement cell = (CellHeaderElement)element.ParentElement;
    
                       IList<Element> children = new List<Element>();
    
                       // read cell from DGN model
                       CellQuery oCellQuery = cell.AsCellQuery();
                       bool res1 = oCellQuery.IsEffectivelyLocked(true, true);
    
                       bool result = oCellQuery.ExposeChildren(ExposeChildrenReason.Edit);
                       ChildElementCollection oComponents = oCellQuery.GetChildren();
    
                       IList<Element> list = new List<Element>();
                       ElementCopyContext copier = new ElementCopyContext(Session.Instance.GetActiveDgnModelRef());
                       copier.WriteElements = false;
                       copier.DisableAnnotationScaling = true;
    
                       for (int i = 0; i < oComponents.Count(); i++)
                       {
                           if (oComponents.ElementAt(i).ElementId == element.ElementId) continue;
                           Element newE = copier.DoCopy(oComponents.ElementAt(i));
    
                           list.Add(newE);
                       }
                       copier.Dispose();
    
                       DPoint3d origin;
                       cell.GetTransformOrigin(out origin);
    
                   } 
                   catch (Exception ex)
                   {
                       ;
                   }

  • Thanks Nenad, looking if there is a parent seems to work well for my situation but your "ChildElementCollection" will definitely come in handy for some other things I'm working on.

Reply Children
No Data