ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / Layout Class / DeleteElements Method / DeleteElements(IEnumerable<Element>) Method
The elements being removed
Example

In This Topic
    DeleteElements(IEnumerable<Element>) Method
    In This Topic
    Deletes the elements from a page layout. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public void DeleteElements( 
       IEnumerable<Element> elements
    )
    Public Overloads Sub DeleteElements( _
       Optional ByVal elements As IEnumerable(Of Element) _
    ) 

    Parameters

    elements
    The elements being removed
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    elements must belong to layout 'URI'
    Remarks
    If elements is null then all elements are deleted.
    If a group element is provided in the list of elements to be deleted then the group element and all its children will be deleted.
    If a child of a group element is provided in the list in addition to its parent then the parent takes precedence (i.e. the entire group element is deleted and not just that child)
    Example
    Delete Layout Elements
    //on the QueuedTask  
    var elementsToRemove = layout.GetSelectedElements();
    layout.DeleteElements(elementsToRemove);
    Delete an element or elements on a layout
    //Delete an element or elements on a layout.
    
    //Perform on the worker thread
    QueuedTask.Run(() =>
    {
      //Delete a specific element on a layout
      aLayout.DeleteElement(elm);
     
      //Or delete a group of elements using a filter
      aLayout.DeleteElements(item => item.Name.Contains("Clone"));
    
      //Or delete all elements on a layout
      aLayout.DeleteElements(item => true);
    });
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also