ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / GraphicsLayerExtensions Class / GetElementsAsFlattenedList Method
The graphics layer being extended
Example

In This Topic
    GetElementsAsFlattenedList Method (GraphicsLayerExtensions)
    In This Topic
    Get the collection of ArcGIS.Desktop.Layouts.GraphicElement from the GraphicsLayer. Nested groups within ArcGIS.Desktop.Layouts.GroupElement are not preserved.
    Syntax
    Public Shared Function GetElementsAsFlattenedList( _
       ByVal graphicsLayer As GraphicsLayer _
    ) As IReadOnlyList(Of GraphicElement)
    public static IReadOnlyList<GraphicElement> GetElementsAsFlattenedList( 
       GraphicsLayer graphicsLayer
    )

    Parameters

    graphicsLayer
    The graphics layer being extended

    Return Value

    Example
    Select Graphic Elements
    {
      var elements = graphicsLayer.GetElementsAsFlattenedList()
                          .Where(e => e.Name.StartsWith("Text"));
      // Note: must be called on the QueuedTask
      {
        graphicsLayer.SelectElements(elements);
        //or select one element
        graphicsLayer.SelectElement(elements.FirstOrDefault());
      }
    }
    Find Graphic elements
    {
      // Note: must be called on the QueuedTask
      {
        //Find elements by name
        var elems = graphicsLayer.FindElements(new List<string>() { "Point 1", "Line 3", "Text 1" });
        //Find elements by type
        //Find all point graphics in the Graphics Layer
        var pointGraphics = graphicsLayer.GetElementsAsFlattenedList().Where(elem => elem.GetGraphic() is CIMPointGraphic);
        //Find all line graphics in the Graphics Layer
        var lineGraphics = graphicsLayer.GetElementsAsFlattenedList().Where(elem => elem.GetGraphic() is CIMLineGraphic);
        //Find all polygon graphics in the Graphics Layer
        var polygonGraphics = graphicsLayer.GetElementsAsFlattenedList().Where(elem => elem.GetGraphic() is CIMPolygonGraphic);
        //Find all text graphics in the Graphics Layer
        var textGraphics = graphicsLayer.GetElementsAsFlattenedList().Where(elem => elem.GetGraphic() is CIMTextGraphic);
        //Find all picture graphics in the Graphics Layer
        var pictureGraphic = graphicsLayer.GetElementsAsFlattenedList().Where(elem => elem.GetGraphic() is CIMPictureGraphic);
      }
    }
    Select Text Graphic Elements
    {
      var all_text = graphicsLayer.GetElementsAsFlattenedList()
                    .Where(e => e.GetGraphic() is CIMTextGraphic);
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also