Is there a way to check if a toolbox tool exists before opening it using the arcgis pro sdk? When I tried OpenToolDialog() on a tool not in the toolbox it tried to open it and failed.
string analysisToolName = "C:\\Program Files\\ArcGIS\\Pro\\Resources\\ArcToolBox\\Toolboxes\\Analysis Tools.tbx\\NewToolBuffer";
var param_values = Geoprocessing.MakeValueArray();
param_values = null;
if (File.Exists(analysisToolName))
{
Debug.WriteLine("FOUND");
Geoprocessing.OpenToolDialog(analysisToolName, param_values);
}
else
{
Debug.WriteLine("DID NOT FIND TOOL");
}
You can use a try/catch statement. The exception can also be used to handle other specific error other than the tool not being loaded.
var param_values = Geoprocessing.MakeValueArray();
param_values = null;
try
{
Geoprocessing.OpenToolDialog(analysisToolName, param_values);
}
catch (Exception e)
{
Debug.WriteLine("DID NOT FIND TOOL");
}
I tried this but when I run OpenToolDialog it is not throwing an exception so it just finishes and I see this. Is there a way to throw an exception when Tool has failed to open happens?