Hello, I am looking to add a new button to the right-click context menu of a geoprocessing (GP) tool to implement a custom GP batch processing feature.
I have already implemented the UI-level button creation and the pop-up window upon clicking. Below is the content of the daml file.
<insertModule id="BatchGeoprocessingClassic_Module" className="Module1" autoLoad="false" caption="Module1">
<controls>
<button id="WWW_GP_Batch_Classic_Button" caption="Batch Process (Classic)" className="GP_Batch_Classic_Button" loadOnClick="true" keytip="z1">
<tooltip heading="Batch Process (Classic)">
</tooltip>
</button>
</controls>
</insertModule>
<updateModule refID="esri_geoprocessing_module">
<menus>
<updateMenu refID="esri_geoprocessing_SystemToolMenu">
<insertButton refID="WWW_GP_Batch_Classic_Button" placeWith="esri_geoprocessing_BatchTool" />
</updateMenu>
</menus>
</updateModule>
Now, I have encountered a problem where I am unable to retrieve the GP tool that was right-clicked, as well as the parameters of the tool. I would like to ask if there is a way in the Pro SDK to obtain the name and parameters of the GP tool when a user right-clicks on it?
It looks like there's a gap in the ArcGIS Pro API. Normally you would call FrameworkApplication.ContextMenuDataContext to get the 'underlying' (to your right click) tool. The problem is that the returned object is an ArcGIS Pro internal class and hence you can't use that class in your add-in. There is a workaround using reflection that allows you to access the underlying 'tool' context. However, be advised that this solution is outside the Pro API framework and hence subject to change. We will submit a new requirement to the Geoprocessing team for consideration. In order to get the current (right clicked) tool insert this code inside your 'OnClick' button function:
protected override void OnClick()
{
try
{
var toolInfo = FrameworkApplication.ContextMenuDataContext; //as ArcGIS.Desktop.GeoProcessing.ToolInfoViewModel;
// internal class ToolInfo:
// public string Name
// public string Description
// public string ToolType
// public bool IsValid
// public string ToolBoxName
// public string FullPath
// public bool IsSystem
// public string toolName
string name = (string)toolInfo.GetType().GetProperty("Name").GetValue(toolInfo, null);
string description = (string)toolInfo.GetType().GetProperty("Description").GetValue(toolInfo, null);
string toolType = (string)toolInfo.GetType().GetProperty("ToolType").GetValue(toolInfo, null);
string toolBoxName = (string)toolInfo.GetType().GetProperty("ToolBoxName").GetValue(toolInfo, null);
string fullPath = (string)toolInfo.GetType().GetProperty("FullPath").GetValue(toolInfo, null);
string toolName = (string)toolInfo.GetType().GetProperty("toolName").GetValue(toolInfo, null);
bool isValid = (bool)toolInfo.GetType().GetProperty("IsValid").GetValue(toolInfo, null);
bool isSystem = (bool)toolInfo.GetType().GetProperty("IsSystem").GetValue(toolInfo, null);
string nl = Environment.NewLine;
MessageBox.Show($@"Type of toolInfo: {toolInfo.GetType().ToString()}{nl}"
+ $@"name: {name}{nl}"
+ $@"description: {description}{nl}"
+ $@"toolType: {toolType}{nl}"
+ $@"toolBoxName: {toolBoxName}{nl}"
+ $@"fullPath: {fullPath}{nl}"
+ $@"toolName: {toolName}{nl}"
+ $@"isValid: {isValid}{nl}"
+ $@"isSystem: {isSystem}{nl}");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Sample output: