GetTemplates Method (MappingExtensions)
Gets all templates for a map member. This method must be called on the MCT. Use QueuedTask.Run.
Find table templates belonging to a standalone table
// retrieve editing templates associated with standalone tables in the active map.
await QueuedTask.Run(() =>
{
//Get a particular table template
var tableTemplate = activeMap.FindStandaloneTables("Address Points").FirstOrDefault()?.GetTemplate("Residences");
//Get all the templates of a standalone table
var ownersTableTemplates = activeMap.FindStandaloneTables("Owners").FirstOrDefault()?.GetTemplates();
var statisticsTableTemplates = activeMap.GetStandaloneTablesAsFlattenedList().First(l => l.Name.Equals("Trading Statistics")).GetTemplates();
});
Activate template and its default editing tool
await QueuedTask.Run(() =>
{
// Get all templates for the layer
var templates = featureLayer.GetTemplates();
if (templates.Count == 0)
return;
// Get the first template - alternatively get a specific template
var template = templates.First();
// Activate the default tool
template.ActivateDefaultToolAsync();
});
Activate template and a specific editing tool
{
await QueuedTask.Run(() =>
{
// DAML ID of the tool to activate - for example "esri_editing_SketchTwoPointLineTool" Pro Tool or a custom tool
string _editToolname = "esri_editing_SketchTwoPointLineTool";
// Get all templates for the layer
var templates = featureLayer.GetTemplates();
if (templates.Count == 0)
return;
// Get the first template - alternatively get a specific template
var template = templates.First();
// Confirm the tool is available in the template
if (template.ToolIDs.FirstOrDefault(_editToolname) == null)
return;
// Activate the tool
template.ActivateToolAsync(_editToolname);
});
}
Activate template and its last selected tool
{
await QueuedTask.Run(() =>
{
// Get all templates for the layer
var templates = featureLayer.GetTemplates();
if (templates.Count == 0)
return;
// Get the first template - alternatively get a specific template
var template = templates.First();
// Activate the last selected/used tool for the template
template.ActivateLastSelectedToolAsync();
});
}
Activate template without changing current tool
{
await QueuedTask.Run(() =>
{
// Get all templates for the layer
var templates = featureLayer.GetTemplates();
if (templates.Count == 0)
return;
// Get the first template - alternatively get a specific template
var template = templates.First();
// Activate the template without changing the current tool
template.ActivateAsync();
});
}
Hide or show editing tools on templates
await QueuedTask.Run(() =>
{
//hide all tools except line tool on a given feature layer
var editTemplates = featureLayer.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
allTools.AddRange(cimEditTemplate.GetExcludedToolIDs().ToList());
cimEditTemplate.SetExcludedToolIDs(allTools.ToArray());
cimEditTemplate.AllowToolID("esri_editing_SketchLineTool");
newCIMEditingTemplates.Add(cimEditTemplate);
}
//update the layer templates
var layerDef = featureLayer.GetDefinition() as CIMFeatureLayer;
// Set AutoGenerateFeatureTemplates to false for template changes to stick
layerDef.AutoGenerateFeatureTemplates = false;
layerDef.FeatureTemplates = newCIMEditingTemplates.ToArray();
featureLayer.SetDefinition(layerDef);
});
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)
ArcGIS Pro version: 3.0 or higher.