How to activate custom MapTool from a DockPane Button?

764
5
Jump to solution
02-15-2021 12:37 PM
nita14
by
Regular Contributor

Hi,

I am struggling with activating a new MapTool item (point sketching on amap) from a button located in a custom Dockpane. Can you please direct me to some code samples or resources on how to do that?

 

Thanks!

 

adam

0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

When you implement a button (or tool) you have to define its 'id' in the config.daml file.  Usually the item template for buttons/tools will define an id for you.  It looks like this:

<tool id="CompReporter_AddCompBySelection" caption="AddCompBySelection" 							 
      className="AddCompBySelection" loadOnClick="true" ...>
          <tooltip ... </tooltip>
</tool>

the 'id' in this case is:  CompReporter_AddCompBySelection

In the 'code behind' for your dockpane you can then use your tool (or button) just like any other ArcGIS Pro button (built-in or not) by using this snippet:

// use CompReporter_AddCompBySelection
IPlugInWrapper wrapper = FrameworkApplication.GetPlugInWrapper("CompReporter_AddCompBySelection");
if (wrapper is ICommand toolCmd)
{
  // if it is a tool, execute will set current tool
  toolCmd.Execute(null);
}

View solution in original post

5 Replies
GintautasKmieliauskas
Regular Contributor
0 Kudos
nita14
by
Regular Contributor

Hi Gintautas,

Thank you for the answer. I believe that the link you mentioned is useful only to activate arcgis pro built-in MapTools. Is it correct?

Thanks!

Adam

0 Kudos
GintautasKmieliauskas
Regular Contributor

Hi,

If I understand your question right then you can activate Esri, your or third-party tools the same way. As described in link. One thing which you need to know it is tool ID. Here is link for Esri tools ID:

https://github.com/Esri/arcgis-pro-sdk/wiki/ArcGIS-Pro-DAML-ID-Reference 

If you can find Esri sketch tool which is useful for your workflow you can activate it. Otherwise your can create your own sketch tool.

Here is the link to related thread:

https://community.esri.com/t5/arcgis-pro-sdk-questions/how-do-i-activate-deactivate-a-maptool/td-p/8... 

Wolf
by Esri Regular Contributor
Esri Regular Contributor

When you implement a button (or tool) you have to define its 'id' in the config.daml file.  Usually the item template for buttons/tools will define an id for you.  It looks like this:

<tool id="CompReporter_AddCompBySelection" caption="AddCompBySelection" 							 
      className="AddCompBySelection" loadOnClick="true" ...>
          <tooltip ... </tooltip>
</tool>

the 'id' in this case is:  CompReporter_AddCompBySelection

In the 'code behind' for your dockpane you can then use your tool (or button) just like any other ArcGIS Pro button (built-in or not) by using this snippet:

// use CompReporter_AddCompBySelection
IPlugInWrapper wrapper = FrameworkApplication.GetPlugInWrapper("CompReporter_AddCompBySelection");
if (wrapper is ICommand toolCmd)
{
  // if it is a tool, execute will set current tool
  toolCmd.Execute(null);
}
nita14
by
Regular Contributor

Thank you @Wolf and @GintautasKmieliauskas for the guidance. It works ok now.

0 Kudos