Using arcpy to open Script tool

1105
3
Jump to solution
12-06-2013 10:33 AM
JensenConnor
New Contributor
Is it possible to use the pythonaddins.GPToolDialog(X,Y) as part of my python addins toolbar script to open a script tool I have stored in a custom toolbox? Where X is a string representing the location of my toolbox and Y is the name of my script tool. I can use this to open geoprocessing tools but have not been able to figure out how to open my script in the toolbox.

Thanks for any ideas you may have.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
TimBarnes
Occasional Contributor III
Is it possible to use the pythonaddins.GPToolDialog(X,Y) as part of my python addins toolbar script to open a script tool I have stored in a custom toolbox? Where X is a string representing the location of my toolbox and Y is the name of my script tool. I can use this to open geoprocessing tools but have not been able to figure out how to open my script in the toolbox.

Thanks for any ideas you may have.


Your script is a 'tool' after you import it/add it into a toolbox so works the same as any other tool- pythonaddins.GPToolDialog() just references the name (Y) of the tool within the toolbox (X). Remember that the tool will display using its 'Label' within the toolbox, but you need to reference the 'Name' so right click on the tool/script that you want to use and inspect the 'Name' value in the 'General' tab. I think you may be trying to use the 'label' which is tripping you up?

View solution in original post

0 Kudos
3 Replies
MaxSquires
Occasional Contributor
If the script tool in question is also a python script you can view its source by looking at the properties context menu of the script tool in arccatalog.

If that is the case, you can explicitly import the script file to your python script by saving a copy of the script in either your python path directory or just right next to (that is, in the same folder) the script you are importing it to like:

import arcpy
import customPyScript


if the name of the script file you are looking for is customPyScript.py

after you import your script you should be able to access its methods by calling it thusly:

customPyScipt.method(input, output)


If you are importing a binary tool from an existing toolbox you should be able to do:

arcpy.ImportToolbox(tbxPath, scriptName)


I might have misunderstood your question.

What do you mean by "open [your] script in the toolbox"?
0 Kudos
TimBarnes
Occasional Contributor III
Is it possible to use the pythonaddins.GPToolDialog(X,Y) as part of my python addins toolbar script to open a script tool I have stored in a custom toolbox? Where X is a string representing the location of my toolbox and Y is the name of my script tool. I can use this to open geoprocessing tools but have not been able to figure out how to open my script in the toolbox.

Thanks for any ideas you may have.


Your script is a 'tool' after you import it/add it into a toolbox so works the same as any other tool- pythonaddins.GPToolDialog() just references the name (Y) of the tool within the toolbox (X). Remember that the tool will display using its 'Label' within the toolbox, but you need to reference the 'Name' so right click on the tool/script that you want to use and inspect the 'Name' value in the 'General' tab. I think you may be trying to use the 'label' which is tripping you up?
0 Kudos
JensenConnor
New Contributor
Tim,

This was exactly it. Simply needed to take out the spaces...ugh. Thanks for the help.
0 Kudos