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

333
1
07-17-2020 05:04 AM
AdamDavis
Occasional Contributor

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

0 Kudos
1 Reply
UmaHarano
Esri Regular Contributor

At 2.6 (released yesterday), a new "GetParent" method is available on the Element class.

0 Kudos