Any model variable can be set as a model parameter. There are two primary reasons to set a model variable as a parameter:
- Output variables that are set as model parameters are added to the map when the model is run as a geoprocessing tool.
- Variables that are set as model parameters appear as tool parameters when the model is run as a geoprocessing tool, allowing you to specify different data or values for your model to process than what was specified when the model was created.
Set model parameters
To set a model variable as a parameter, the model must be edited in ModelBuilder. In ModelBuilder, right-click the variable and select Parameter. When a variable is set as a parameter, the letter P appears next to the variable in the model.
The name of the variable is used as the model parameter label. You can rename a model parameter by renaming the model variable in ModelBuilder. Right-click the variable, select Rename, and enter the new name. When you open the model tool in the Geoprocessing pane, the parameter name reflects the new name. The value of a variable is used as the default value for the corresponding model parameter. If the variable has no value in ModelBuilder, the model parameter will be blank.
For the outputs of your model tool to appear in the geoprocessing history, you must set those outputs as model parameters. For example, if your tool outputs an HTML file and you want the user to be able to click to open the file from the Geoprocessing History pane, you must set the HTML output file as a model parameter.
Model parameter properties
You can change several properties of model parameters using the model Properties window. These properties impact how the parameters appear when the model tool is opened in the Geoprocessing pane.
Right-click the model tool in a toolbox and select Properties, or if you are editing the model in ModelBuilder, click the Properties button on the ModelBuilder ribbon.
Change the order of the parameters by dragging the parameters to the new order on the Parameters tab in the tool's Properties window.
- Required—The parameter must have a value for the tool to run.
- Optional—The parameter does not require a value.
- Derived—Use derived parameters for the following cases:
- The output is the same as the input. For example, the Calculate Field tool updates the values of a field in the input table—it doesn't create a table or modify the schema of the input.
- The tool modifies the schema of the input. For example, the Add Field tool adds a field to the input table.
- The tool outputs a scalar value such as a number, string, or Boolean value. For example, the Get Count tool returns a derived integer value.
- The tool creates an output from values in other parameters. For example, the Create Feature Class tool returns a derived feature class path constructed from other parameters that have path and name values.
- The tool will create data in a known location. For example, you may have a script that creates a feature class in a known workspace. Neither the feature class nor the workspace are parameter options.
The designation of required, optional, and derived occurs automatically based on how the parameter is used in the model. For example, if the variable is used as the input to a required parameter of a tool in the model, that model parameter will be required. You can change model parameters from optional to required for the model tool, but you cannot change required parameters to optional.
To change an optional parameter to a required parameter, set the Type option to Required on the Parameters tab of the tool's Properties window.
This property defines whether the parameter is an input to the tool or an output of the tool.
If the parameter type is Derived, the parameter direction will be automatically set to Output.
All script tools should have output parameters so they can be used in ModelBuilder. The fundamental idea of ModelBuilder is to connect the output of tools to inputs of other tools, and if your script tool doesn't have an output parameter, it isn't very useful in ModelBuilder. The output might be a dataset that is entered in a parameter value, a derived output where the location or name is determined within the script, or a derived value that is calculated or determined. At the very least, you can output a Boolean containing true if the tool completed successfully, and false otherwise.
Parameters can be assigned a category. Categorized parameters are displayed in a drop-down section when the tool is opened in the Geoprocessing pane.
Parameter filters are used to limit or restrict the input values or data that can be specified for a model tool parameter. For example, the Value List filter requires that only values from a list can be specified for the parameter. Values entered into a parameter that do not match the filter will cause an error; the model cannot be executed until a valid value is entered.
The following filters are available:
- Value list—A list of predefined keywords. You can set a value list filter for string and numeric model parameters.
- Range—The minimum and maximum numeric value. The range is inclusive, meaning both the minimum and maximum are valid choices.
- Feature class—A list of allowable feature shape types, including point, multipoint, polyline, polygon, and multipatch.
- File—A list of valid file extensions such as .txt or .gpx.
Do not enter the period for the extension. For example, type txt, not .txt. Separate list values with a semicolon (;). For example, to allow both .txt and .csv files, type txt; csv.
- Field—A list of allowable field types, including short, long, single, double, test, date, OID, geometry, BLOB, raster, GUID, global ID, and XML.
- Workspace—The type of allowable workspace, including file system, local geodatabase, and enterprise geodatabase.
You can make a parameter dependent on another parameter. The typical use for this is to make one parameter that accepts an attribute field dependent on another parameter that is a feature class or table; the field parameter will include a drop-down list of attribute fields from the dependent parameter.
You can save a layer file with a defined symbology and use that layer file as a template for how your model outputs will be symbolized when added to a map. This can be accomplished in two ways:
- Set the Symbology option of an output parameter to a layer file path such as C:\Data\LandUseOverlay\Symbolized.lyrx on the Parameters tab of the tool's Properties window.
- Add the Apply Symbology From Layer tool to the end of your model, and set the Symbology Layer parameter to a layer file path.