ArcGIS Pro 3.1 API Reference Guide
ArcGIS.Core.Data.Mapping Namespace / AnnotationFeature Class / GetGraphic Method
Example

In This Topic
    GetGraphic Method (AnnotationFeature)
    In This Topic
    Gets a ArcGIS.Core.CIM.CIMGraphic for the feature. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public CIMGraphic GetGraphic()
    Public Function GetGraphic() As CIMGraphic

    Return Value

    A ArcGIS.Core.CIM.CIMGraphic for the feature.
    Exceptions
    ExceptionDescription
    A geodatabase-related exception has occurred.
    Example
    Rotate or Move the Annotation
          await QueuedTask.Run(() =>
          {
              //Don't use 'Shape'....Shape is the bounding box of the annotation text. This is NOT what you want...
              //
              //var insp = new Inspector();
              //insp.Load(annoLayer, oid);
              //var shape = insp["SHAPE"] as Polygon;
              //...wrong shape...
    
              //Instead, we must get the TextGraphic from the anno feature.
              //The TextGraphic shape will be the anno baseline...
              //At 2.1 the only way to retrieve this textLine is to obtain the TextGraphic from the AnnotationFeature
              QueryFilter qf = new QueryFilter()
              {
                  WhereClause = "OBJECTID = 1"
              };
    
      //annoLayer is ~your~ Annotation layer
    
      using (var rowCursor = annoLayer.Search(qf))
      {
        if (rowCursor.MoveNext())
        {
          using (var annoFeature = rowCursor.Current as 
                      ArcGIS.Core.Data.Mapping.AnnotationFeature)
          {
            var graphic = annoFeature.GetGraphic();
            var textGraphic = graphic as CIMTextGraphic;
            var textLine = textGraphic.Shape as Polyline;
            // rotate the shape 90 degrees
            var origin = GeometryEngine.Instance.Centroid(textLine);
            Geometry rotatedPolyline = GeometryEngine.Instance.Rotate(textLine, origin, System.Math.PI / 2);
            //Move the line 5 "units" in the x and y direction
            //GeometryEngine.Instance.Move(textLine, 5, 5);
    
            EditOperation op = new EditOperation();
            op.Name = "Change annotation angle";
            op.Modify(annoLayer, oid, rotatedPolyline);
            op.Execute();
          }
        }
      }
    });
    
    Get the Annotation Text Graphic
    await QueuedTask.Run(() =>
    {
        using (var table = annoLayer.GetTable())
        {
            using (var rc = table.Search())
            {
                rc.MoveNext();
                using (var af = rc.Current as AnnotationFeature)
                {
                    var graphic = af.GetGraphic();
                    var textGraphic = graphic as CIMTextGraphic;
    
                    //Note: 
                    //var outline_geom = af.GetGraphicOutline(); 
                    //gets the anno text outline geometry...
                }
            }
        }
    });
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also