Friday, August 1, 2014

GIS 5103 Module 10: Creating Custom Tools

Script tool messages after replacing print with arcpy.AddMessage().


Dialog box of script tool parameters.


While Python scripting for ArcMap allows one much more freedom to create functions not otherwise available, using and editing Python script requires a degree of knowledge and experience.  Fortunately, it is possible to import a stand-alone Python script into a toolbox as a script tool that is more easily shared with and used by others, regardless of their knowledge of Python.  Our exercise and assignment this week taught us to create and edit such script tools.

Although creating a script tool is a relatively simple matter, it does require a few steps to ensure the tool works properly without further editing the script itself.  After importing the script as a script tool into a toolbox, one must set up the properties and parameters of the tool.  The parameters include all the variables for the tool (inputs, outputs, etc.) as well as their data types.  This sets up the dialog box within the ArcMap GUI, but the Python code itself must be edited to accord with these parameters to allow users to successful enter variables into the tool.  This is accomplished by using the GetParameter or GetParameterAsText functions.  These are numbered in parentheses in the order they appear in the dialog box, starting with zero.  This will allow the script tool to function with custom inputs from the user.  The only remaining task is to use the AddMessage function rather than print to display the tool's messages in the results window.

No comments:

Post a Comment