How do I activate the construction tool for a specific layer in code?

515
1
Jump to solution
06-06-2019 02:13 AM
MortenJespersen1
New Contributor III

I have a map project with some business layers that my users want to edit. For that, the users sometimes need to sketch a support line in a temporary layer. When they are satisfied with the support line, they edit objects in the business layers by tracing along the support line. It sounds like a backwards way of doing things, I know, but it actually makes sense, when the edits you are doing are complex, and sometimes depends on a lot of different background data. 

 

Now, my problem is, that I want to activate the construction tool for the support layer by the click of a button. I don't want the user to go into the Create Features tab, and activate it there. Actually, I'd prefer to hide the Create Features tab entirely by configuration, but I can only do that if I can activate construction in code. However, I haven't been able to find examples on how to do this. So now, i turn to you, dear  colleagues, in the hope that you can help me. 

0 Kudos
1 Solution

Accepted Solutions
MortenJespersen1
New Contributor III

I found the solution. Maybe someone can use it in the future: 

private void ActivateConstructionTool(string targetLayerName)

{

QueuedTask.Run(() =>
{
   var map = ArcGIS.Desktop.Mapping.MapView.Active.Map;
   if (map == null)
      return;

   foreach (Layer layer in map.GetLayersAsFlattenedList())
   {
      if (layer.Name.Equals(targetLayerName))
      {
         var myTemplates = layer.GetTemplates();
         var myTemplate = myTemplates.ToList()[0];

         myTemplate.ActivateDefaultToolAsync();
         break;
      }
   }

});

}

View solution in original post

0 Kudos
1 Reply
MortenJespersen1
New Contributor III

I found the solution. Maybe someone can use it in the future: 

private void ActivateConstructionTool(string targetLayerName)

{

QueuedTask.Run(() =>
{
   var map = ArcGIS.Desktop.Mapping.MapView.Active.Map;
   if (map == null)
      return;

   foreach (Layer layer in map.GetLayersAsFlattenedList())
   {
      if (layer.Name.Equals(targetLayerName))
      {
         var myTemplates = layer.GetTemplates();
         var myTemplate = myTemplates.ToList()[0];

         myTemplate.ActivateDefaultToolAsync();
         break;
      }
   }

});

}

0 Kudos