ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / GroupElement Class
Members Example

In This Topic
    GroupElement Class
    In This Topic
    Represents a group element that appears in the layout contents pane. Represents a group element
    Object Model
    GroupElement ClassCoordinate2D StructureEnvelope ClassCIMElement ClassGeometry ClassIElementContainer Interface
    Syntax
    Remarks

    It is possible that group elements can be nested in another group element. If the element container is a Layout then the element gets added to the root level of the layout TOC at the top most position. If the element container is a GroupElement then it gets added to the group at the topmost position.

    The FindElement method will also find elements nested in a group element.

    If you want to work with all the elements within a group element, use the Elements property to return the collection of elements in a group element.

    Example
    Create_Empty_Group_Root
    //Create an empty group element at the root level of the contents pane.
    
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //At 2.x - GroupElement emptyGroupAtRoot = LayoutElementFactory.Instance.CreateGroupElement(layout);
      //         emptyGroupAtRoot.SetName("Empty group at root");
      GroupElement emptyGroupAtRoot = ElementFactory.Instance.CreateGroupElement(layout, null, "Empty group at root");
    });
    Create_Empty_Group_Group
    //Create an empty group element at the root level of another group element.
    
    //Find an existing group element
    GroupElement existingGroupAtRoot = layout.FindElement("Empty group at root") as GroupElement;
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //At 2.x - GroupElement emptyGroupInGroupAtRoot = LayoutElementFactory.Instance.CreateGroupElement(existingGroupAtRoot);
      //         emptyGroupInGroupAtRoot.SetName("Empty group in group at root");
      GroupElement emptyGroupInGroupAtRoot = ElementFactory.Instance.CreateGroupElement(
                                              existingGroupAtRoot, null, "Empty group in group at root");
    
    });
    Create_Group_With_Single_Element_Root
    //Create a group with a single element at the root level of the contents pane.
    
    //Find an existing element
    Element titleElm = layout.FindElement("Title") as Element;
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //At 2.x - GroupElement groupWithSingleElementAtRoot = LayoutElementFactory.Instance.CreateGroupElement(layout, titleElm);
      //         groupWithSingleElementAtRoot.SetName("Group with single element at root"); 
      GroupElement groupWithSingleElementAtRoot = 
               ElementFactory.Instance.CreateGroupElement(layout, new List<Element>() { titleElm }, "Group with single element at root");
    });
    Create_Group_With_List_Elements_Root
    //Create a group with a list of elements at the root level of the contents pane.
    
    //Find an existing elements
    Element scaleBar = layout.FindElement("Scale Bar") as Element;
    Element northArrow = layout.FindElement("North Arrow") as Element;
    Element legend = layout.FindElement("Legend") as Element;
    
    //Build a list and add the elements
    List<Element> elmList = new List<Element>
    {
      scaleBar,
      northArrow,
      legend
    };
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //At 2.x - GroupElement groupWithListOfElementsAtRoot = LayoutElementFactory.Instance.CreateGroupElement(layout, elmList);
      //         groupWithListOfElementsAtRoot.SetName("Group with list of elements at root");
      GroupElement groupWithListOfElementsAtRoot = 
        ElementFactory.Instance.CreateGroupElement(layout, elmList, "Group with list of elements at root");
    });
    Create_Group_With_List_Element_Names_Root
    //Create a group using a list of element names at the root level of the contents pane.
    
    //Build list of element names
    var elmNameList = new[] { "Table Frame", "Chart Frame" };
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //GroupElement groupWithListOfElementNamesAtRoot = LayoutElementFactory.Instance.CreateGroupElement(layout, elmNameList);
      //groupWithListOfElementNamesAtRoot.SetName("Group with list of element names at root");
    
      //At 3.x use FindElements to retrieve the respective elements first
      var elems = layout.FindElements(elmNameList);
      GroupElement groupWithListOfElementNamesAtRoot =
        ElementFactory.Instance.CreateGroupElement(layout, elems, "Group with list of element names at root");
    });
    Creating empty group elements
    //Create an empty group element at the root level of the contents pane
    
    //Create on worker thread
    await QueuedTask.Run(() =>
    {
      //At 2.x - GroupElement grp1 =
      //             LayoutElementFactory.Instance.CreateGroupElement(layout);
      //         grp1.SetName("Group"); 
    
      //container is IElementContainer - GroupLayer or Layout
      GroupElement grp1 = ElementFactory.Instance.CreateGroupElement(
                            container, null, "Group");
    });
    
    // *** or ***
    
    //Create a group element inside another group element
    
    //Find an existing group element
    //container is IElementContainer - GroupLayer or Layout
    GroupElement existingGroup = container.FindElement("Group") as GroupElement;
    
    //Create on worker thread
    await QueuedTask.Run(() =>
    {
      //At 2.x - GroupElement grp2 =
      //      LayoutElementFactory.Instance.CreateGroupElement(existingGroup);
      //         grp2.SetName("Group in Group");
      GroupElement grp2 = ElementFactory.Instance.CreateGroupElement(
        existingGroup, null, "Group in Group");
    });
    Create a group element with elements
    //Create a group with a list of elements at the root level of the contents pane.
    
    //Find an existing elements
    //container is IElementContainer - GroupLayer or Layout
    var elem1 = container.FindElement("Polygon 1");
    var elem2 = container.FindElement("Bezier Text");
    var elem3 = container.FindElement("Cloud Shape 2");
    
    //Construct a list and add the elements
    var elmList = new List<Element>
    {
      elem1,
      elem2,
      elem3
    };
    
    //Perform on the worker thread
    await QueuedTask.Run(() =>
    {
      //At 2.x - GroupElement groupWithListOfElementsAtRoot =
      //             LayoutElementFactory.Instance.CreateGroupElement(layout, elmList);
      //groupWithListOfElementsAtRoot.SetName("Group with list of elements at root");
      //
      GroupElement groupWithListOfElementsAtRoot =
              ElementFactory.Instance.CreateGroupElement(
                       container, elmList, "Group with list of elements at root");
    });
    
    // *** or ***
    
    //Create a group using a list of element names at the root level of the contents pane.
    
    //List of element names
    var elmNameList = new[] { "Para Text1", "Line 3" };
    
    //Perform on the worker thread
    await QueuedTask.Run(() =>
    {
      //At 2.x - GroupElement groupWithListOfElementNamesAtRoot =
      //   LayoutElementFactory.Instance.CreateGroupElement(layout, elmNameList);
      //         groupWithListOfElementNamesAtRoot.SetName(
      //                  "Group with list of element names at root");
    
      //At 3.x, use the names to find the relevant elements first
      //container is IElementContainer - GroupLayer or Layout
      var elems = container.FindElements(elmNameList);
      GroupElement groupWithListOfElementNamesAtRoot =
          ElementFactory.Instance.CreateGroupElement(
               container, elems, "Group with list of element names at root");
    });
    Inheritance Hierarchy

    System.Object
       ArcGIS.Desktop.Framework.Contracts.PropertyChangedBase
          ArcGIS.Desktop.Layouts.Element
             ArcGIS.Desktop.Layouts.GroupElement
                ArcGIS.Desktop.Reports.ReportSectionElement

    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also