ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.CIM Namespace / Anchor Enumeration
Example Example

In This Topic
    Anchor Enumeration
    In This Topic
    A list of anchor positions for an element on a page layout.
    Syntax
    Members
    MemberDescription
    BottomLeftCorner Bottom, left corner.
    BottomMidPoint Bottom, middle location.
    BottomRightCorner Bottom, right corner.
    CenterPoint Center location.
    LeftMidPoint Left, middle location.
    RightMidPoint Right, middle location.
    TopLeftCorner Top, left corner.
    TopMidPoint Top, middle location.
    TopRightCorner Top, right corner.
    Unspecified Unspecified.
    Example
    Create Point Element
    {
      //Note: Must be on QueuedTask.Run(() => { ...
    
      //Build geometry
      Coordinate2D coord2D = new Coordinate2D(2.0, 10.0);
    
      //Reference a point symbol in a style
      StyleProjectItem stylePrjItm = Project.Current.GetItems<StyleProjectItem>()
                .FirstOrDefault(item => item.Name == "ArcGIS 2D");
      SymbolStyleItem symStyleItm = stylePrjItm.SearchSymbols(
                            StyleItemType.PointSymbol, "City Hall")[0];
      CIMPointSymbol pointSym = symStyleItm.Symbol as CIMPointSymbol;
      pointSym.SetSize(50);
    
      var elemInfo = new ElementInfo()
      {
        CustomProperties = new List<CIMStringMap>() {
        new CIMStringMap() { Key = "Key1", Value = "Value1"},
        new CIMStringMap() { Key = "Key2", Value = "Value2"}
      },
        Anchor = Anchor.TopRightCorner,
        Rotation = 45.0
      };
    
      var graphic = GraphicFactory.Instance.CreateSimpleGraphic(
                                    coord2D.ToMapPoint(), pointSym);
    
      ElementFactory.Instance.CreateGraphicElement(
        layout, graphic, "New Point", true, elemInfo);
    }
    Create Rectangle Element
    {
      //Note: Must be on QueuedTask.Run
    
      //Build geometry
      Coordinate2D ll = new Coordinate2D(1.0, 4.75);
      Coordinate2D ur = new Coordinate2D(3.0, 5.75);
      Envelope env = EnvelopeBuilderEx.CreateEnvelope(ll, ur);
    
      //Set symbology, create and add element to layout
      CIMStroke outline = SymbolFactory.Instance.ConstructStroke(
        ColorFactory.Instance.BlackRGB, 5.0, SimpleLineStyle.Solid);
      CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(
        ColorFactory.Instance.GreenRGB, SimpleFillStyle.DiagonalCross, outline);
    
      var ge = GraphicFactory.Instance.CreateSimpleGraphic(env, polySym);
      var elemInfo = new ElementInfo()
      {
        Anchor = Anchor.CenterPoint,
        Rotation = 45.0,
        CornerRounding = 5.0
      };
    
      ElementFactory.Instance.CreateGraphicElement(
        layout, env, polySym, "New Rectangle", false, elemInfo);
    }
    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);
    }
    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);
        }
      }
    Inheritance Hierarchy

    System.Object
       System.ValueType
          System.Enum
             ArcGIS.Core.CIM.Anchor

    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also