ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / MappingExtensions Class / CreateTemplate Method / CreateTemplate(MapMember,String,String,Inspector,String,String[],String[]) Method
The map member the new template is to be added to.
The template name.
Optional description of the template.
An ArcGIS.Desktop.Editing.Attributes.Inspector object containing default template values.
Optional, If not provided will use the default tool for the map member type. The defaultTool can be specified using daml-id.
Optional. A set of tags.
Optional list of tools to not allow for this template. Tool filters can be specified using daml-id.
Example

In This Topic
    CreateTemplate(MapMember,String,String,Inspector,String,String[],String[]) Method
    In This Topic
    Creates a new template using the specified definition. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Overloads Shared Function CreateTemplate( _
       ByVal mapMember As MapMember, _
       ByVal templateName As String, _
       Optional ByVal description As String, _
       Optional ByVal inspector As Inspector, _
       Optional ByVal defaultTool As String, _
       Optional ByVal tags() As String, _
       Optional ByVal toolFilter() As String _
    ) As EditingTemplate

    Parameters

    mapMember
    The map member the new template is to be added to.
    templateName
    The template name.
    description
    Optional description of the template.
    inspector
    An ArcGIS.Desktop.Editing.Attributes.Inspector object containing default template values.
    defaultTool
    Optional, If not provided will use the default tool for the map member type. The defaultTool can be specified using daml-id.
    tags
    Optional. A set of tags.
    toolFilter
    Optional list of tools to not allow for this template. Tool filters can be specified using daml-id.

    Return Value

    The newly created template. Null if it cannot be created.
    Exceptions
    ExceptionDescription
    The Template name cannot be empty. And the template name must be unique.
    Example
    Create New Template using layer.CreateTemplate
    var layer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault();
    if (layer == null)
      return;
    QueuedTask.Run(() =>
    {
      var insp = new Inspector();
      insp.LoadSchema(layer);
    
      insp["Field1"] = value1;
      insp["Field2"] = value2;
      insp["Field3"] = value3;
    
      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 = layer.CreateTemplate("My new template", "description", insp, defaultTool, tags, toolFilter);
    });
    Create New Table Template using table.CreateTemplate
    var table = MapView.Active.Map.GetStandaloneTablesAsFlattenedList().FirstOrDefault();
    if (table == null)
      return;
    QueuedTask.Run(() =>
    {
      var tableTemplate = table.GetTemplate("Template1");
      
      var definition = tableTemplate.GetDefinition();
      definition.Description = "New definition";
      definition.Name = "New name";
      //Create new table template using this definition
      table.CreateTemplate(definition);
    
      //You can also create a new table template using this extension method. You can use this method the same way you use the layer.CreateTemplate method.
      table.CreateTemplate("New template name", "Template description", tags: new string[] { "tag 1", "tag 2" });
    });
    Create Annotation Template
    // get an anno layer
    AnnotationLayer annoLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<AnnotationLayer>().FirstOrDefault();
    if (annoLayer == null)
      return;
    
    QueuedTask.Run(() =>
    {
      Inspector insp = null;
      // get the anno feature class
      var fc = annoLayer.GetFeatureClass() as ArcGIS.Core.Data.Mapping.AnnotationFeatureClass;
    
      // get the featureclass 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(annoLayer);
    
      // 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 = annoLayer.CreateTemplate("new anno template", "description", insp, defaultTool, tags, toolFilter);
    });
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also