ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Editing.Attributes Namespace / Inspector Class / LoadSchema Method / LoadSchema(MapMember) Method
Example

In This Topic
    LoadSchema(MapMember) Method
    In This Topic
    Load the schema of a mapMember into the inspector. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public void LoadSchema( 
       MapMember member
    )
    Public Overloads Sub LoadSchema( _
       ByVal member As MapMember _
    ) 

    Parameters

    member
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Example
    Get a layers schema using Inspector
    // Loads the schema of the specified feature layer and iterates through its attributes,  providing access to their properties such as field name, alias, type, and other metadata.
    await QueuedTask.Run(() =>
    {
      // create an instance of the inspector class
      var inspector = new Inspector();
      // load the layer
      inspector.LoadSchema(featureLayer);
      // iterate through the attributes, looking at properties
      foreach (var attribute in inspector)
      {
        var fldName = attribute.FieldName;
        var fldAlias = attribute.FieldAlias;
        var fldType = attribute.FieldType;
        int idxFld = attribute.FieldIndex;
        var fld = attribute.GetField();
        var isNullable = attribute.IsNullable;
        var isEditable = attribute.IsEditable;
        var isVisible = attribute.IsVisible;
        var isSystemField = attribute.IsSystemField;
        var isGeometryField = attribute.IsGeometryField;
      }
    });
    Adds a custom validation rule to the "Mineral" field of the specified feature layer.
    await QueuedTask.Run(() =>
    {
      var insp = new Inspector();
      insp.LoadSchema(featureLayer);
    
      bool success = insp.TrySetValue("mineral", "Salt");
      object result = null;
      success = insp.TryGetValue("mineral", out result);
      if (result != null && success)
      {
        MessageBox.Show($"Successfully stored and retrieved the value of field 'Mineral': {result.ToString()}");
      }
    
      var attrib = insp.Where(a => a.FieldName == "Mineral").First();
      attrib.AddValidate(() =>
      {
        if (attrib.CurrentValue.ToString() == "Salt")
        {
          return [];
        }
        else
        {
          return [ArcGIS.Desktop.Editing.Attributes.Attribute.ValidationError.Create("Error", Severity.Low)];
        }
      });
    });
    Create New Template using layer.CreateTemplate
    await QueuedTask.Run(() =>
      {
        var newFieldValues = new object[] { "Value1", 123, DateTime.Now };
        // Creates a new editing template for the specified feature layer with the provided field values.
        var insp = new Inspector();
        insp.LoadSchema(featureLayer);
    
        insp["Field1"] = newFieldValues[0];
        insp["Field2"] = newFieldValues[1];
        insp["Field3"] = newFieldValues[2];
    
        var tags = new[] { "Polygon", "tag1", "tag2" };
    
        // set defaultTool using a daml-id
        string defaultTool = "esri_editing_SketchCirclePolygonTool";
    
        // tool filter is the tools to filter OUT
        var toolFilter = new[] { "esri_editing_SketchTracePolygonTool" };
    
        // create a new template
        var newTemplate = featureLayer.CreateTemplate("My new template", "description", insp, defaultTool, tags, toolFilter);
      });
    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
        }
      });
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also