Select to view content in your preferred language

Remove all construction tools

486
11
Jump to solution
09-10-2024 08:27 AM
JonathanDewalt
Occasional Contributor

Has anybody got this sample to work? I want to be able to remove all construction tools and only use the my custom tools but I can't seem to find a way to remove the default tools without having to manually enter the ID for each and everytool.  This example off ESRI web page shows featLayer.GetTemplates but the GetTemplates function does not exist.

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);
});

   

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
JonathanDewalt
Occasional Contributor

Got it working.  My code was missing the ArcGIS .Desktop.Extensions reference.

View solution in original post

0 Kudos
11 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

GetTemplates is static function of MappingExtensions class with MapMember type parameter. You need to add using :

using ArcGIS.Desktop.Mapping;

There are 2 alternatives to use GetTemplates method:

var editTemplates = featLayer.GetTemplates();
// or
var editTemplates1 = MappingExtensions.GetTemplates(featLayer);

 

0 Kudos
JonathanDewalt
Occasional Contributor
Hello,
I am using ArcGIS.Desktop.Mapping but it says GetTemplates does not exist and MappingExtensions also does not exist in ArcGIS.Desktop.Mapping
0 Kudos
GKmieliauskas
Esri Regular Contributor

What ArcGIS Pro SDK version do you use? 

0 Kudos
JonathanDewalt
Occasional Contributor
Using 3.0 and also tried in 3.3
0 Kudos
GKmieliauskas
Esri Regular Contributor

I have tested on 3.1 and it works

0 Kudos
UmaHarano
Esri Regular Contributor

Hi @JonathanDewalt 

When I run the tool, the Create features pane needed to be open.  If it was not open, the code did not work. In your scenario, was the Create Features pane open?

0 Kudos
JonathanDewalt
Occasional Contributor
Right now it won’t even compile as it says the GetTemplates does not exist even though I am using ArcGis.desktop.mapping
0 Kudos
UmaHarano
Esri Regular Contributor

Would it be possible for you to zip up your code and send it over as an attachment?

0 Kudos
JonathanDewalt
Occasional Contributor

Here is a sample test class.  I get compiler errors stating that MappingExtensions and GetTemplates do not exist. 

using ArcGIS.Core.CIM;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace rmg.AlbertaWildfireTools.Core
{
public class Test
{

public static async Task SetConstructionToolsAsync(object sender, Layer layer, CancellationToken cancellationToken = default(CancellationToken))
{
await QueuedTask.Run(() => SetConstructionTools(sender, layer, cancellationToken));
}

public static void SetConstructionTools(object sender, Layer featLayer, CancellationToken cancellationToken = default(CancellationToken))
{

try
{
//self-documenting thread check
if (!QueuedTask.OnWorker) throw new ArcGIS.Core.CalledOnWrongThreadException();

if (cancellationToken.IsCancellationRequested == true)
{
rmg.Common.Events.ProgressBarEvents.OnTaskCancelled(sender);
return;
}

// var featLayer = MapView.Active.Map.FindLayers("Roads").First();


var x = MappingExtensions.GetTemplates(featLayer);
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("rmg_AlbertaWildfireTools_Buttons_Editing_ConstructionTool_FireLine");
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);


}
catch (Exception ex)
{
rmg.Common.Events.ProgressBarEvents.OnTaskCancelled(sender);
// errorHandler.WriteError(ex, "kkkkfeer");
return;
}

}

}
}

 

0 Kudos