A quick tour of creating script tools
Scripts that you create can be executed with one of two basic methods: outside ArcGIS and within ArcGIS.
- Outside ArcGIS means that the script is executed from the operating system command prompt, as shown below, or within a development application, like PythonWin. Scripts executed in this manner are referred to as stand-alone scripts.
- Within ArcGIS means you create a script tool inside a toolbox. A script tool is like any other tool—it can be opened and executed from the tool dialog box, used in models and the Python window, and called from other scripts and script tools.
Creating a script tool for your script is easy, and there are many advantages to doing so.
- A script tool that you create is an integral part of geoprocessing, just like a system tool—you can open it from the Search or Catalog window, use it in ModelBuilder and the Python window, and call it from another script.
- You can write messages to the progress dialog box and the Results window.
- Using the built-in documentation tools, you can provide documentation.
- When the script is run as a script tool, the arcpy object you import is fully aware of the application it was called from, such as ArcMap. All environment settings made in the application, such as arcpy.env.overwriteOutput and arcpy.env.scratchWorkspace , are available from the geoprocessing object you create.
To create a script tool, you need three things:
- A script
- A custom toolbox
- A precise definition of the parameters of your script
To create a script tool, right-click your custom toolbox and click Add > Script. This opens the Add Script wizard that takes you step by step through the process of creating a script tool. After completing the steps, your toolbox will contain a new script tool. You can always modify properties (such as parameter names and data types) of this script tool by right-clicking the script tool and choosing Properties.
The table below guides you to topics that show you how to create script tools.
This topic shows you how to create a custom toolbox to contain your script tool. |
|
The parameters of your script tool need to be precisely defined. This topic is all about how you define parameters. |
|
This topic explains the Add Script wizard and what it requires. |
|
This topic describes how to open your script for editing. |
|
Debugging script tools | This topic explains how to debug your script tool. |
This topic is all about defining and setting parameters. |
|
Because your script will be executed from an ArcGIS application, such as ArcMap or ArcCatalog, you can write messages to the progress dialog box. |
|
You can make your script tools run faster by running them in process. This topic describes in-process execution. |
|
Customizing script tool behavior |
You can customize how your script tool dialog box appearance changes based on user input. For example, you can enable parameters, provide default values, and restrict parameter values to be only certain types (for example, only allow point feature classes to be input). You can also define properties of your tool output for use in ModelBuilder. These three topics show you how this is done using a special Python class called ToolValidator. |
You can associate a layer file (.lyr) with an output parameter to define the symbology used to display the output. This topic shows you how this is done from a script. |
|
Rather than having a separate script file on disk, you can embed your script with the tool. You can also protect your script from viewing by using a password. |