ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / Layout Class / FindElements Method
The names of the elements to find. Cannot be null
Example

In This Topic
    FindElements Method (Layout)
    In This Topic
    Finds the elements recursively with the given names on the page layout.
    Syntax

    Parameters

    elementNames
    The names of the elements to find. Cannot be null

    Return Value

    A IList or an empty list if no elements are found
    Exceptions
    ExceptionDescription
    Value cannot be null: elementNames
    Remarks
    Find recurses nested groups to find the given elements.
    Example
    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 = layout.FindElement("Polygon 1");
      var elem2 = layout.FindElement("Bezier Text");
      var elem3 = layout.FindElement("Cloud Shape 2");
    
      //Construct a list and add the elements
      var elmList = new List<Element>
      {
        elem1,
        elem2,
        elem3
      };
      //Note: Must be on QueuedTask.Run
    
      GroupElement groupWithListOfElementsAtRoot =
                ElementFactory.Instance.CreateGroupElement(
                         layout, 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" };
    
      //Note: Must be on QueuedTask.Run
    
      var elemToGroup = layout.FindElements(elmNameList);
      GroupElement groupWithListOfElementNamesAtRoot =
            ElementFactory.Instance.CreateGroupElement(
                 layout, elemToGroup, "Group with list of element names at root");
    }
    Find layout elements
    {
      //Note: Must be on QueuedTask.Run
      //Find elements by name
      var layoutElementsToFind = layout.FindElements(new List<string>() { "Point 1", "Line 3", "Text 1" });
      //Get the collection of elements from the page layout. Nesting within GroupElement is preserved.
      var elementCollection = layout.GetElements();
      //Get the collection of Element from the page layout as a flattened list. Nested groups within GroupElement are not preserved.
      var elements = layout.GetElementsAsFlattenedList();
      //Convert collection of the elements to a collection of GraphicElements.
      var graphicElements = elements.ToList().ConvertAll(x => (GraphicElement)x);
      //Find elements by type
      //Find all point graphics in the Layout
      var pointGraphics = graphicElements.Where(elem => elem.GetGraphic() is CIMPointGraphic);
      //Find all line graphics in the Graphics Layer
      var lineGraphics = graphicElements.Where(elem => elem.GetGraphic() is CIMLineGraphic);
      ////Find all polygon graphics in the Graphics Layer
      var polyGraphics = graphicElements.Where(elem => elem.GetGraphic() is CIMPolygonGraphic);
      ////Find all text graphics in the Graphics Layer
      var textGraphics = graphicElements.Where(elem => elem.GetGraphic() is CIMTextGraphic);
      ////Find all picture graphics in the Graphics Layer
      var pictureGraphic = graphicElements.Where(elem => elem.GetGraphic() is CIMPictureGraphic);
    }
    UnSelect elements on the Layout
    {
      //Unselect one element.
      var elementToUnSelect = layout.FindElements(new List<string>() { "MyPoint" }).FirstOrDefault();
      layout.UnSelectElement(elementToUnSelect);
      //Unselect multiple elements.
      var elementsToUnSelect = layout.FindElements(new List<string>() { "Point 1", "Line 3", "Text 1" });
      layout.UnSelectElements(elementsToUnSelect);
    }
    UnSelect elements on the LayoutView
    {
      //Unselect one element.
      var elementToUnSelectInView = layout.FindElements(new List<string>() { "MyPoint" }).FirstOrDefault();
      layoutView.UnSelectElement(elementToUnSelectInView);
      //Unselect multiple elements.
      var elementsToUnSelectInView = layout.FindElements(new List<string>() { "Point 1", "Line 3", "Text 1" });
      layoutView.UnSelectElements(elementsToUnSelectInView);
    }
    Zoom to elements
    {
      LayoutView lytView = LayoutView.Active;
      //Zoom to an element
      var elementToZoomTo = layout.FindElements(new List<string>() { "MyPoint" }).FirstOrDefault();
      lytView.ZoomToElement(elementToZoomTo);
      //Zoom to  multiple elements.
      var elementsToZoomTo = layout.FindElements(new List<string>() { "Point 1", "Line 3", "Text 1" });
      lytView.ZoomToElements(elementsToZoomTo);
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also