You can provide custom behavior for your own geoprocessing tool, such as enabling and disabling parameters, providing default values, and updating string keywords. By adding Python code, you can do the following:
- Update a parameter filter. Using a field filter, you can create a list of valid field types, such as Long and Double. With a string filter, you can set a list of valid keywords. There are six types of filters: Value List, Range, Feature Class, File, Field, and Workspace.
- Provide default values for parameters, such as cell size for rasters.
- Customize warning and error messages.
- Enable or disable a parameter based on values contained in other parameters.
Note:
When a parameter is disabled, it will disappear from view on the Geoprocessing pane, and when reenabled, it will reappear. The same effect is seen on several system geoprocessing tools such as the Add Field tool in which several parameters are dependent on the field type.
- Update the description of output datasets for use in ModelBuilder. By updating the description, subsequent tools in ModelBuilder can identify expected data characteristics before a tool is run.
How validation works
Validation is performed with a block of Python code that geoprocessing uses to control how the Geoprocessing pane and Python window change based on user input.
Validation
Validation means checking that all tool parameters are correct and providing useful messages if they are not. The following are the two parts to validation:
- Validation that ArcGIS Pro does automatically. This part of validation is referred to as internal validation.
- Validation that you can do by adding code.
Internal validation does the following:
- If a parameter is required, the parameter is evaluated to determine whether a value has been provided. If a value has not been provided, a message is produced.
- Checks that the value is of the correct type. For example, entering a raster instead of a feature class, or a string instead of a number.
- Checks filter membership; that is, if you have a Value List filter containing keywords, such as RED, ORANGE, and YELLOW, and you enter BLUE, you'll receive an error message.
- Checks the existence of input datasets.
- Generates a default path for output datasets.
- Updates the description of the output data based on a set of rules contained in the Schema object.
- Checks the existence of output datasets using the Allow geoprocessing tools to overwrite existing datasets option. If the dataset exists and the option is false, an error is produced; otherwise, a warning is produced.
- If the parameter is a Field data type, checks that the field exists in the associated table.
- Checks that the output dataset isn't the same as the input dataset.
- For parameters containing linear and areal unit data types, sets their default values by examining the corresponding values in ArcGIS Pro (if running from ArcGIS Pro).
You can custom validation to do the following:
- Update filters based on interaction with other parameters. For example, if your user enters a point feature class in the first parameter, you want the third parameter to display one set of choices. If a polygon feature class is entered, you want to display a different set of choices in the third parameter.
- Enable and disable parameters.
- Calculate default values.
- Perform any tool-specific parameter interaction.
The code you add works with internal validation as follows:
- You can provide a set of rules that internal validation uses for updating the description of output datasets. These rules are contained in the Schema object.
- You can update filters before internal validation occurs. Internal validation compares the value the user entered with the values in the filter.
You can configure your validation code to calculate default values, enable and disable parameters, and customize messages. These types of actions have no consequence for internal validation.