List Toolbox then Run

499
2
12-05-2012 01:14 PM
ShaunWeston
Occasional Contributor
I'm trying to figure out how to call a tool from another tool in python. In my python script of got something similar to the code below to get a list of all tools and I basically want the script to run them all automatically, but can't figure out how. So basically what is going to happen is someone will create a new tool in the toolbox and this will automatically be added to the process and run automatically without having to alter the code.

So my question is does anyone know how to automatically run a custom python tool? I can get a list of the tools in the toolbox, just not sure how to get them to run automatically.


import arcpy
# Create a list of the conversion tools#
tools = arcpy.ListTools("*_conversion")
# Loop through the list and print each tool's usage#   
e.g., 'Usage: merge <inputs;inputs...> <output> {field_mappings}'#
for tool in tools:    
print arcpy.Usage(tool)
Tags (2)
0 Kudos
2 Replies
JoelCalhoun
New Contributor III
If you need to pass parameters to your other tools you might want to take a look at this thread:

http://gis.stackexchange.com/questions/11339/arcpy-and-running-python-scripts-with-parameters-within...
0 Kudos
ShaunWeston
Occasional Contributor
Thanks that is helpful, but that post does get a bit complicated and hard to follow. I've got a solution that is working, but I'd like to be able to do one more thing and that is dynamically name a tool from python code. So I import a toolbox in python then I've got this line:

arcpy.SelectProperty_toolbox(valuationID,"","",buffer,"")

and "SelectProperty" is the name of the script. I want this name to be generated dynamically from the code. So if I could have that bit as a variable like this:

arcpy.{variable}_toolbox(valuationID,"","",buffer,"")

that would be great, but don't know how to do it?
0 Kudos