Tuesday, May 3, 2011

Calling Tools and Models from Python

In general, Python is only aware of the out of the box geoprocessing functionality and not custom tools created by the end user. These tools can by accessed via Python much like the 'import' method used in the last post.  To access a custom made toolbox and tool from Python use the ImportToolbox().  After importing the toolbox, the custom tools can be accessed as:

>>> arcpy.ImportToolbox(".tbx")
# Run the imported tool
#
>>> arcpy.toolname_alias(parameters)


When accessing tools using the arcpy package, the toolbox alias is extremely important. If a unique name is not used, then the system will not know what tool to run.

When working with server, published geoprocessing tasks can be imported as well:

>>> arcpy.ImportToolbox("http://server/arcgis/services;BufferByVal")


Enjoy