Defines how a new feature is created for a particular
MapMember.
Find edit template by name on a layer
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
//get the templates
var map = ArcGIS.Desktop.Mapping.MapView.Active.Map;
if (map == null)
return;
var mainTemplate = map.FindLayers("main").FirstOrDefault()?.GetTemplate("Distribution");
var mhTemplate = map.FindLayers("Manhole").FirstOrDefault()?.GetTemplate("Active");
});
Find table templates belonging to a standalone table
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
var map = ArcGIS.Desktop.Mapping.MapView.Active.Map;
if (map == null)
return;
//Get a particular table template
var tableTemplate = map.FindStandaloneTables("Address Points").FirstOrDefault()?.GetTemplate("Residences");
//Get all the templates of a standalone table
var ownersTableTemplates = map.FindStandaloneTables("Owners").FirstOrDefault()?.GetTemplates();
var statisticsTableTemplates = MapView.Active.Map.GetStandaloneTablesAsFlattenedList().First(l => l.Name.Equals("Trading Statistics")).GetTemplates();
});
Change Default Edit tool for a template
public Task ChangeTemplateDefaultToolAsync(ArcGIS.Desktop.Mapping.FeatureLayer flayer,
string toolContentGUID, string templateName)
{
return ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
// retrieve the edit template form the layer by name
var template = flayer?.GetTemplate(templateName) as ArcGIS.Desktop.Editing.Templates.EditingTemplate;
// get the definition of the layer
var layerDef = flayer?.GetDefinition() as ArcGIS.Core.CIM.CIMFeatureLayer;
if ((template == null) || (layerDef == null))
return;
if (template.DefaultToolID != this.ID)
{
bool updateLayerDef = false;
if (layerDef.AutoGenerateFeatureTemplates)
{
layerDef.AutoGenerateFeatureTemplates = false;
updateLayerDef = true;
}
// retrieve the CIM edit template definition
var templateDef = template.GetDefinition();
// assign the GUID from the tool DAML definition, for example
// <tool id="TestConstructionTool_SampleSDKTool" categoryRefID="esri_editing_construction_polyline" ….>
// <tooltip heading="">Tooltip text<disabledText /></tooltip>
// <content guid="e58239b3-9c69-49e5-ad4d-bb2ba29ff3ea" />
// </tool>
// then the toolContentGUID would be "e58239b3-9c69-49e5-ad4d-bb2ba29ff3ea"
//At 2.x -
//templateDef.ToolProgID = toolContentGUID;
templateDef.DefaultToolGUID = toolContentGUID;
// set the definition back to
template.SetDefinition(templateDef);
// update the layer definition too
if (updateLayerDef)
flayer.SetDefinition(layerDef);
}
});
}
Change Default Edit tool for a template
public Task ChangeTemplateDefaultToolAsync(ArcGIS.Desktop.Mapping.FeatureLayer flayer,
string toolContentGUID, string templateName)
{
return ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
// retrieve the edit template form the layer by name
var template = flayer?.GetTemplate(templateName) as ArcGIS.Desktop.Editing.Templates.EditingTemplate;
// get the definition of the layer
var layerDef = flayer?.GetDefinition() as ArcGIS.Core.CIM.CIMFeatureLayer;
if ((template == null) || (layerDef == null))
return;
if (template.DefaultToolID != this.ID)
{
bool updateLayerDef = false;
if (layerDef.AutoGenerateFeatureTemplates)
{
layerDef.AutoGenerateFeatureTemplates = false;
updateLayerDef = true;
}
// retrieve the CIM edit template definition
var templateDef = template.GetDefinition();
// assign the GUID from the tool DAML definition, for example
// <tool id="TestConstructionTool_SampleSDKTool" categoryRefID="esri_editing_construction_polyline" ….>
// <tooltip heading="">Tooltip text<disabledText /></tooltip>
// <content guid="e58239b3-9c69-49e5-ad4d-bb2ba29ff3ea" />
// </tool>
// then the toolContentGUID would be "e58239b3-9c69-49e5-ad4d-bb2ba29ff3ea"
//At 2.x -
//templateDef.ToolProgID = toolContentGUID;
templateDef.DefaultToolGUID = toolContentGUID;
// set the definition back to
template.SetDefinition(templateDef);
// update the layer definition too
if (updateLayerDef)
flayer.SetDefinition(layerDef);
}
});
}
Hide or show editing tools on templates
QueuedTask.Run(() =>
{
//hide all tools except line tool on layer
var featLayer = MapView.Active.Map.FindLayers("Roads").First();
var editTemplates = featLayer.GetTemplates();
var newCIMEditingTemplates = new List<CIMEditingTemplate>();
foreach (var et in editTemplates)
{
//initialize template by activating default tool
et.ActivateDefaultToolAsync();
var cimEditTemplate = et.GetDefinition();
//get the visible tools on this template
var allTools = et.ToolIDs.ToList();
//add the hidden tools on this template
allTools.AddRange(cimEditTemplate.GetExcludedToolIDs().ToList());
//hide all the tools then allow the line tool
//At 2.x -
//allTools.AddRange(cimEditTemplate.GetExcludedToolDamlIds().ToList());
allTools.AddRange(cimEditTemplate.GetExcludedToolIDs().ToList());
//At 2.x -
//cimEditTemplate.SetExcludedToolDamlIds(allTools.ToArray());
//cimEditTemplate.AllowToolDamlID("esri_editing_SketchLineTool");
cimEditTemplate.SetExcludedToolIDs(allTools.ToArray());
cimEditTemplate.AllowToolID("esri_editing_SketchLineTool");
newCIMEditingTemplates.Add(cimEditTemplate);
}
//update the layer templates
var layerDef = featLayer.GetDefinition() as CIMFeatureLayer;
// Set AutoGenerateFeatureTemplates to false for template changes to stick
layerDef.AutoGenerateFeatureTemplates = false;
layerDef.FeatureTemplates = newCIMEditingTemplates.ToArray();
featLayer.SetDefinition(layerDef);
});
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" });
});
Target Platforms: Windows 11, Windows 10, Windows 8.1