Select to view content in your preferred language

Check if toolbox tool exists before opening it

903
2
08-17-2019 01:36 PM
MapVis
by
Emerging Contributor

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

Tags (1)
0 Kudos
2 Replies
LanceCole
MVP Regular Contributor

Map Vis 

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");
}‍‍‍‍‍‍‍‍‍‍
0 Kudos
MapVis
by
Emerging Contributor

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?

0 Kudos