ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / Element Class / SetX Method
Double
Example

In This Topic
    SetX Method (Element)
    In This Topic
    Sets the X position of the element. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Overridable Sub SetX( _
       ByVal x As Double _
    ) 
    public virtual void SetX( 
       double x
    )

    Parameters

    x
    Double
    Exceptions
    ExceptionDescription
    This method must be called within the lambda passed to QueuedTask.Run.
    This element requires its mapview to be active
    Remarks
    Placement for an element contained in graphics layer requires the mapview be active. To change the element X and Y consider SetAnchorPoint
    Example
    Create Point Text Element 1
    {
      //Create a simple point text element and assign basic symbology and text settings.
    
      //Note: Must be on QueuedTask.Run
      //Build 2D point geometry
      Coordinate2D coord2D = new Coordinate2D(3.5, 10);
    
      //Set symbology, create and add element to layout
      CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(
                    ColorFactory.Instance.RedRGB, 32, "Arial", "Regular");
      string textString = "Point text";
    
      //use ElementInfo to set placement properties during create
      var elemInfo = new ElementInfo()
      {
        Anchor = Anchor.CenterPoint,
        Rotation = 45
      };
      var ptTxtElm = ElementFactory.Instance.CreateTextGraphicElement(
        layout, TextType.PointText, coord2D.ToMapPoint(), sym, textString,
                           "New Point Text", true, elemInfo);
    
      //Change additional text properties
      ptTxtElm.SetX(4.5);
      ptTxtElm.SetY(9.5);
    }
    Create North Arrow From StyleItem 2
    {
      //Note: 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 = layout.FindElement("Map Frame") 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 text element properties
    {
      //Update text element properties for an existing text element.
      //Note: Must be on QueuedTask.Run
      // Reference and load the layout associated with the layout item
      if (layout != null)
      {
        // Reference a text element by name
        TextElement txtElm = layout.FindElement("MyTextElement") as TextElement;
        if (txtElm != null)
        {
          double x = 2.0;
          double y = 3.0;
          // Change placement properties
          txtElm.SetAnchor(Anchor.CenterPoint);
          txtElm.SetX(x);
          txtElm.SetY(y);
    
          // Change TextProperties
          TextProperties txtProperties = new TextProperties(
                            "Hello world", "Times New Roman", 48, "Regular");
          txtElm.SetTextProperties(txtProperties);
        }
      }
    Clone an element
    {
      //Clone a layout graphic element and apply an offset.
      //Note: Must be on QueuedTask.Run
    
      // Reference a graphic element by name
      GraphicElement graphicElement =
                          layout.FindElement("MyElement") as GraphicElement;
      if (graphicElement != null)
      {
    
        //Clone and set the new x,y
        GraphicElement cloneElement = graphicElement.Clone("Clone");
        double xOffset = 0;
        double yOffset = 0;
        cloneElement.SetX(cloneElement.GetX() + xOffset);
        cloneElement.SetY(cloneElement.GetY() + yOffset);
      }
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also