Tool parameters are used to set values for elements within a script, allowing you to pick from a drop-down list or navigate to a location without having to edit any script code.
Embellishing from my previous blog on listing files in a folder using Python, this blog shows you how to create a script that allows you to interact with a dialog (figure 1) instead of editing source code. In this example I show how you can navigate to the workspace to search, select the type of file to list, and specify where the output text file will be written to.
Figure 1. Script user-interface.
Setting Parameters in ArcCatalog
First you need to add an empty script tool to a Toolbox in ArcCatalog following the process in the Adding a script tool section of the ArcGIS 10 help. You can then start to create parameters within the Script Properties of the tool.
1. Right-click the Script Tool to bring up “Script Properties”. To edit/create Parameters go to the “Parameters” tab (figure 2). The Display Name values appear in the dialog as field labels; while the type of data expected is defined in the Data Type column.
Figure 2. Script parameters.
2. Each Parameter has additional properties that are set in the “Parameter Properties”. These define whether the parameter is input/output, required/optional, multivalue or not (see Table 1 for this script’s parameter properties). For a full discussion of these parameter properties see the ArcGIS10 help article Setting script tool parameters.
Table 1. Parameter properties.
3. Further Parameters are set in the “Value List” filter which enables a List of Values to appear in a drop-down list on the input window:
Figure 3. Value List used in this script.
This value list determines the content of the drop-down list in the Option field (shown in Figure 1).
Now that you have set up the parameters for the tool you can write a script to use them. This process has been spilt into 4 parts to help with description and readability. You can download this script to save you typing it in.
Running this script will write results to the previously defined location (see OutputFile field in Figure 1) and will produce a text file like the one shown in Figure 4. This is readable in ArcCatalog and can be imported into Microsoft Excel.
Figure 4. Export results.
Note that the validation tab in the tool properties has not been used, so you will have to define the text file output type by appending the suffix “.txt” to the file name. Further information on validation can be found at the Customizing script tool behaviour section of the ArcGIS 10 help.
Finally, many thanks to my colleague Adrian Birch for his help in putting this blog together.
Posted by Simon Kettle, GIS Technician, Exprodat.