ArcGIS Pro 3.1 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.
    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.
    //Change the element's anchor position
    //Perform on the worker thread
    await QueuedTask.Run(() =>
      Anchor elmAnchor = element.GetAnchor();
      elmAnchor = Anchor.CenterPoint;
      element.SetAnchor(elmAnchor); //You don't have to get to set; a shortcut would be: element.SetAnchor(Anchor.CenterPoint);
    Create Point Element
    //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;
    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);
      container, graphic, "New Point", true, elemInfo);
    Create Rectangle Element
    //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 symbolology, 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
      container, env, polySym, "New Rectangle", false, elemInfo);
    Create Point Text Element 1
    //Create a simple point text element and assign basic symbology and text settings.
    //Construct on the worker thread
    await QueuedTask.Run(() =>
      //Build 2D point geometry
      Coordinate2D coord2D = new Coordinate2D(3.5, 10);
      //Set symbolology, create and add element to layout
      CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(
                    ColorFactory.Instance.RedRGB, 32, "Arial", "Regular");
      string textString = "Point text";
      //At 2.x - GraphicElement ptTxtElm =
      //         LayoutElementFactory.Instance.CreatePointTextGraphicElement(
      //                           layout, coord2D, textString, sym);
      //ptTxtElm.SetName("New Point Text");
      //use ElementInfo to set placement properties during create
      var elemInfo = new ElementInfo()
        Anchor = Anchor.CenterPoint,
        Rotation = 45
      var ptTxtElm = ElementFactory.Instance.CreateTextGraphicElement(
        container, TextType.PointText, coord2D.ToMapPoint(), sym, textString,
                           "New Point Text", true, elemInfo);
      //Change additional text properties
    Update text element properties
    //Update text element properties for an existing text element.
    // Reference a layoutitem in a project by name
    LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>()
                          .FirstOrDefault(item => item.Name.Equals("MyLayout"));
    if (layoutItem != null)
      //Perform on the worker thread
      QueuedTask.Run(() =>
        // Reference and load the layout associated with the layout item
        Layout layout = layoutItem.GetLayout();
        if (layout != null)
          // Reference a text element by name
          TextElement txtElm = layout.FindElement("MyTextElement") as TextElement;
          if (txtElm != null)
            // Change placement properties
            // Change TextProperties
            TextProperties txtProperties = new TextProperties(
                             "Hello world", "Times New Roman", 48, "Regular");
    Inheritance Hierarchy



    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also