ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Editing.Attributes Namespace / Inspector Class / GetAnnotationProperties Method
Example

In This Topic
    GetAnnotationProperties Method
    In This Topic
    Gets the ArcGIS.Desktop.Editing.AnnotationProperties for annotation features in the inspector. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Function GetAnnotationProperties() As AnnotationProperties
    public AnnotationProperties GetAnnotationProperties()

    Return Value

    The annotation properties for the features currently loaded in the inspector.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Example
    Create Annotation Template
    // Creates a new annotation template for the specified annotation layer.
    await QueuedTask.Run(() =>
      {
        Inspector insp = null;
        // get the anno feature class
        var fc = annotationLayer.GetFeatureClass() as ArcGIS.Core.Data.Mapping.AnnotationFeatureClass;
    
        // get the feature class CIM definition which contains the labels, symbols
        var cimDefinition = fc.GetDefinition() as ArcGIS.Core.Data.Mapping.AnnotationFeatureClassDefinition;
        var labels = cimDefinition.GetLabelClassCollection();
        var symbols = cimDefinition.GetSymbolCollection();
    
        // make sure there are labels, symbols
        if (labels.Count == 0 || symbols.Count == 0)
          return;
    
        // find the label class required
        //   typically you would use a subtype name or some other characteristic
        // in this case lets just use the first one
    
        var label = labels[0];
    
        // each label has a textSymbol
        // the symbolName *should* be the symbolID to be used
        var symbolName = label.TextSymbol.SymbolName;
        int symbolID = -1;
        if (!int.TryParse(symbolName, out symbolID))
        {
          // int.TryParse fails - attempt to find the symbolName in the symbol collection
          foreach (var symbol in symbols)
          {
            if (symbol.Name == symbolName)
            {
              symbolID = symbol.ID;
              break;
            }
          }
        }
        // no symbol?
        if (symbolID == -1)
          return;
    
        // load the schema
        insp = new Inspector();
        insp.LoadSchema(annotationLayer);
    
        // ok to assign these fields using the inspector[fieldName] methodology
        //   these fields are guaranteed to exist in the annotation schema
        insp["AnnotationClassID"] = label.ID;
        insp["SymbolID"] = symbolID;
    
        // set up some additional annotation properties
        AnnotationProperties annoProperties = insp.GetAnnotationProperties();
        annoProperties.FontSize = 36;
        annoProperties.TextString = "My Annotation feature";
        annoProperties.VerticalAlignment = VerticalAlignment.Top;
        annoProperties.HorizontalAlignment = HorizontalAlignment.Justify;
    
        insp.SetAnnotationProperties(annoProperties);
    
        var tags = new[] { "Annotation", "tag1", "tag2" };
    
        // use daml-id rather than guid
        string defaultTool = "esri_editing_SketchStraightAnnoTool";
    
        // tool filter is the tools to filter OUT
        var toolFilter = new[] { "esri_editing_SketchCurvedAnnoTool" };
    
        // create a new template 
        var newTemplate = annotationLayer.CreateTemplate("new annotation template", "description", insp, defaultTool, tags, toolFilter);
      });
    Programmatically Create an Annotation Feature
    await QueuedTask.Run(() =>
      {
        // annotationLayer is ~your~ Annotation layer...
        // annotationPoint is ~your~ Annotation's location geometry ...
        var op = new EditOperation();
        // Use the inspector
        var insp = new Inspector();
        insp.LoadSchema(annotationLayer);
        // get the annotation properties from the inspector
        AnnotationProperties annoProperties = insp.GetAnnotationProperties();
        // change the annotation text 
        annoProperties.TextString = DateTime.Now.ToLongTimeString();
        // change font color to green
        annoProperties.Color = ColorFactory.Instance.GreenRGB;
        // change the horizontal alignment
        annoProperties.HorizontalAlignment = HorizontalAlignment.Center;
        annoProperties.Shape = annotationPoint;
        // set the annotation properties back on the inspector
        insp.SetAnnotationProperties(annoProperties);
        // create the annotation
        op.Create(annotationLayer, insp);
        if (!op.IsEmpty)
        {
          var result = op.Execute(); //Execute and ExecuteAsync will return true if the operation was successful and false if not
        }
      });
    Update Annotation Text
    // Updates the text of an annotation feature in the specified annotation layer.
    await QueuedTask.Run(() =>
    {
      // annotationLayer is ~your~ Annotation layer...
      // use the inspector methodology
      var insp = new Inspector();
      insp.Load(annotationLayer, objectId);
      // get the annotation properties
      AnnotationProperties annoProperties = insp.GetAnnotationProperties();
      // set the attribute
      annoProperties.TextString = annotationText;
      // assign the annotation properties back to the inspector
      insp.SetAnnotationProperties(annoProperties);
      //create and execute the edit operation
      EditOperation op = new EditOperation();
      op.Name = "Update annotation";
      op.Modify(insp);
      if (!op.IsEmpty)
      {
        var result = op.Execute(); //Execute and ExecuteAsync will return true if the operation was successful and false if not
      }
    });
    Modify Annotation Shape
    // Modifies the geometry of an annotation feature in the specified annotation layer.
    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(annotationLayer, objectId);
      //var shape = insp["SHAPE"] as Polygon;
      //...wrong shape...
      //Instead, we must use the AnnotationProperties
      //annotationLayer is ~your~ Annotation layer
      var insp = new Inspector();
      insp.Load(annotationLayer, objectId);
      AnnotationProperties annoProperties = insp.GetAnnotationProperties();
      var shape = annoProperties.Shape;
      if (shape.GeometryType != GeometryType.GeometryBag)
      {
        var newGeometry = GeometryEngine.Instance.Move(shape, 10, 10);
        annoProperties.Shape = newGeometry;
        insp.SetAnnotationProperties(annoProperties);
        EditOperation op = new EditOperation
        {
          Name = "Change annotation angle"
        };
        op.Modify(insp);
        if (!op.IsEmpty)
        {
          var result = op.Execute(); //Execute and ExecuteAsync will return true if the operation was successful and false if not
        }
      }
    });
    Modify Annotation Text Graphic
    // Modifies the text graphic of a selected annotation feature in the specified annotation layer.
    await QueuedTask.Run(() =>
    {
      var selection = annotationLayer.GetSelection();
      if (selection.GetCount() == 0)
        return;
      // use the first selected feature 
      var insp = new Inspector();
      insp.Load(annotationLayer, selection.GetObjectIDs().FirstOrDefault());
      // getAnnoProperties should return null if not an annotation feature
      AnnotationProperties annoProperties = insp.GetAnnotationProperties();
      // get the textGraphic
      CIMTextGraphic textGraphic = annoProperties.TextGraphic;
      // change text
      textGraphic.Text = "Hello world";
      // set x,y offset via the symbol
      var symbol = textGraphic.Symbol.Symbol;
      var textSymbol = symbol as CIMTextSymbol;
      textSymbol.OffsetX = 2;
      textSymbol.OffsetY = 3;
      textSymbol.HorizontalAlignment = HorizontalAlignment.Center;
      // load the updated textGraphic
      annoProperties.LoadFromTextGraphic(textGraphic);
      // assign the annotation properties back 
      insp.SetAnnotationProperties(annoProperties);
      EditOperation op = new EditOperation
      {
        Name = "modify symbol"
      };
      op.Modify(insp);
      if (!op.IsEmpty)
      {
        bool result = op.Execute(); //Execute and ExecuteAsync will return true if the operation was successful and false if not
      }
    });
    Annotation Construction Tool
    //In your config.daml...set the categoryRefID
    //<tool id="..." categoryRefID="esri_editing_construction_annotation" caption="Create Anno" ...>
    
    //Sketch type Point or Line or BezierLine in the constructor...
    public class ProSnippetAnnotationConstructionTool : MapTool
    {
      public ProSnippetAnnotationConstructionTool()
      {
        IsSketchTool = true;
        UseSnapping = true;
        SketchType = SketchGeometryType.Point;
      }
    
      /// <summary>
      /// Handles the completion of a sketch operation and creates an annotation feature based on the provided geometry.
      /// </summary>
      protected async override Task<bool> OnSketchCompleteAsync(Geometry geometry)
      {
        if (CurrentTemplate == null || geometry == null)
          return false;
        // Create an edit operation
        var createOperation = new EditOperation
        {
          Name = string.Format("Create {0}", CurrentTemplate.Layer.Name),
          SelectNewFeatures = true
        };
        var insp = CurrentTemplate.Inspector;
        var result = await QueuedTask.Run(() =>
        {
          // get the annotation properties class
          AnnotationProperties annoProperties = insp.GetAnnotationProperties();
          // set custom annotation properties
          annoProperties.TextString = "my custom text";
          annoProperties.Color = ColorFactory.Instance.RedRGB;
          annoProperties.FontSize = 24;
          annoProperties.FontName = "Arial";
          annoProperties.HorizontalAlignment = HorizontalAlignment.Right;
          annoProperties.Shape = geometry;
          // assign annotation properties back to the inspector
          insp.SetAnnotationProperties(annoProperties);
          // Queue feature creation
          createOperation.Create(CurrentTemplate.Layer, insp);
          if (!createOperation.IsEmpty)
          {
            // Execute the operation
            return createOperation.Execute(); //Execute and ExecuteAsync will return true if the operation was successful and false if not
          }
          else
            return false;
        });
        return result;
      }
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also