AnsweredAssumed Answered

Is there an easy way to get the Group from an Element

Question asked by AdamDavis on Jul 17, 2020
Latest reply on Jul 29, 2020 by UHarano-esristaff

Hi,

 

I can do this manually but is there an easier way? Can either Container or Parent be made Public please?

 

public static GroupElement FindElementGroup(this Layout layout, Element elementToFind)
        {
            foreach (GroupElement groupElement in layout.GetNestedElements().OfType<GroupElement>().ToList())
            {
                if (groupElement.Elements.Any(element => element.Name.Equals(elementToFind.Name)))
                {
                    return groupElement;
                }
            }
            return null;
        }

public static List<Element> GetNestedElements(this ILayoutElementContainer elementContainer)
        {
            List<Element> elements = elementContainer.Elements.ToList();
            foreach (GroupElement groupElement in elementContainer.Elements.OfType<GroupElement>())
            {
                elements.AddRange(groupElement.GetNestedElements());
            }
            return elements;
        }

 

Adam

Outcomes