ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / GraphicsLayerExtensions Class / FindElements Method
The graphics layer being extended
The names of the elements to find. Cannot be null
Example

In This Topic
    FindElements Method (GraphicsLayerExtensions)
    In This Topic
    Finds the elements recursively with the given names within the GraphicsLayer collection. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax

    Parameters

    graphicsLayer
    The graphics layer being extended
    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
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Value cannot be null: elementNames
    Remarks
    Find recurses nested groups to find the given elements.
    The map view displaying the graphics layer should be initialized.Find recurses nested groups to find the given elements.
    The map view displaying the graphics layer should be initialized.
    Example
    Copy Graphic elements
    //on the QueuedTask
    var elems = sourceGraphicsLayer.FindElements(new List<string>() { "Point 1", "Line 3", "Text 1" });
    var copiedElements = targetGraphicsLayer.CopyElements(elems);
    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);
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also