ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / Element Class / SetName Method
String
Example

In This Topic
    SetName Method (Element)
    In This Topic
    Sets the name of the element. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public void SetName( 
       string name
    )
    Public Sub SetName( _
       ByVal name As String _
    ) 

    Parameters

    name
    String
    Exceptions
    ExceptionDescription
    This method must be called within the lambda passed to QueuedTask.Run.
    Remarks
    All elements on a layout must have a unique name so they can be easily referenced.
    Example
    Element_SetName
    //Modify an element's name.
    
    //Perform on the worker thread
    await QueuedTask.Run(() =>
    {
      element.SetName("New Name");
    });
    Create Legend 2
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    Coordinate2D ll = new Coordinate2D(6, 2.5);
    Coordinate2D ur = new Coordinate2D(8, 4.5);
    Envelope env = EnvelopeBuilderEx.CreateEnvelope(ll, ur);
    
    //Reference MF, create legend and add to layout
    MapFrame mf = layout.FindElement(mapFrameName) as MapFrame;
    var surroundInfo = new LegendInfo()
    {
      MapFrameName = mf.Name
    };
    
    var legendElm = ElementFactory.Instance.CreateMapSurroundElement(
      layout, env.Center, surroundInfo) as Legend;
    legendElm.SetName("New Legend");
    Create North Arrow From StyleItem 2
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    Coordinate2D center = new Coordinate2D(7, 5.5);
    
    //Reference a North Arrow in a style
    StyleProjectItem stylePrjItm = Project.Current.GetItems<StyleProjectItem>()
                                   .FirstOrDefault(item => item.Name == "ArcGIS 2D");
    NorthArrowStyleItem naStyleItm = stylePrjItm.SearchNorthArrows(
                                           "ArcGIS North 10")[0];
    
    //Reference MF, create north arrow and add to layout 
    //var mf = container.FindElement("New Map Frame") as MapFrame;
    var mf = layout.FindElement(MapFrameName) as MapFrame;
    var narrow_info = new NorthArrowInfo()
    {
      MapFrameName = mf.Name,
      NorthArrowStyleItem = naStyleItm
    };
    var arrowElm = (NorthArrow)ElementFactory.Instance.CreateMapSurroundElement(
      layout, center.ToMapPoint(), narrow_info) as NorthArrow;
    arrowElm.SetName("New North Arrow");
    arrowElm.SetHeight(1.75);
    arrowElm.SetX(7);
    arrowElm.SetY(6);
    Update element properties
    //Update an element's properties.
    
    //Performed on worker thread
    QueuedTask.Run(() =>
    {
      // update an element's name
      element.SetName("New Name");
    
      // update and element's visibility
      element.SetVisible(true);
    });
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also