Understanding script tool parameters

Almost all tools have parameters, and you set their values on the tool dialog box or within a script. When the tool is executed, the parameter values are sent to your tool's source code. Your script reads these values and proceeds with its work.

The illustration below shows a script tool dialog box with three parameters: an input workspace, a clip feature class, and an output workspace. All feature classes in the input workspace are clipped to the clip feature class (using the Clip tool) and written to the output workspace.

Script tool parameters

Parameter order must match

The parameter order on the tool dialog box must match the parameter order in your script. If, for example, you change the Clip Features from parameter 2 to parameter 1 in the script tool, you must also change the parameter order in the script tool's properties.

Parameter data types

Every script tool parameter has an associated data type. When the script tool dialog box is opened, geoprocessing uses the data type to check the parameter value. For example, if you enter a feature class for a parameter with a workspace data type, geoprocessing generates an error (a red X on the dialog box), as shown below.

Geoprocessing generates an error when data types don't match

The data type is also used in browsing for data—only data that matches the parameter data type will be shown in the browse dialog box.

Browsing based on data type

Another way to think about parameters and data types is that geoprocessing does not send values to your script that are of the incorrect data type. This is one distinct advantage to creating a script tool—the parameter value is checked against the parameter data type before the value is sent to your script.

Related Topics

3/25/2013