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

GetElementsAsFlattenedList Method (GraphicsLayerExtensions)
Get the collection of ArcGIS.Desktop.Layouts.GraphicElement from the GraphicsLayer. Nested groups within ArcGIS.Desktop.Layouts.GroupElement are not preserved.
Syntax
public static IReadOnlyList<GraphicElement> GetElementsAsFlattenedList( 
   GraphicsLayer graphicsLayer
)

Parameters

graphicsLayer
The graphics layer being extended

Return Value

Example
Select Graphic Elements
var graphicsLayer = MapView.Active.Map.GetLayersAsFlattenedList()
                    .OfType<ArcGIS.Desktop.Mapping.GraphicsLayer>().FirstOrDefault();
if (graphicsLayer == null)
  return;
var elements = graphicsLayer.GetElementsAsFlattenedList()
                    .Where(e => e.Name.StartsWith("Text"));
QueuedTask.Run(() =>
{
  graphicsLayer.SelectElements(elements);
  //or select one element
  graphicsLayer.SelectElement(elements.FirstOrDefault());
});
Find Graphic elements
//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 graphicsLayer = MapView.Active.Map.GetLayersAsFlattenedList()
                    .OfType<ArcGIS.Desktop.Mapping.GraphicsLayer>().FirstOrDefault();
if (graphicsLayer == null)
  return;
var all_text = graphicsLayer.GetElementsAsFlattenedList()
              .Where(e => e.GetGraphic() is CIMTextGraphic);
Requirements

Target Platforms: Windows 11, Windows 10, Windows 8.1

ArcGIS Pro version: 2.6 or higher.
See Also