Geoprocessing tools can be run in a batch mode that allows you to run the tool multiple times using many input datasets or different parameter settings. This makes it possible to run a tool many times with very little interaction. For example, you can run the Clip tool in batch mode to clip several layers to the same study area.
A batch is defined as a number of iterations of a given tool. One of the selected tool's parameters drives the batch and changes per iteration while the remaining tool parameters are constant for all iterations in the batch. In the example above, the batch will have three iterations of the Clip tool. Each iteration runs the Clip tool using one of the layers in the Batch Input Features parameter, and all other parameters remain the same across the iterations.
Not all geoprocessing tools support batch mode. Most notably, the following types of tools do not support batch:
To open and run a tool in batch mode, do the following:
- Find the geoprocessing tool you want to use.
- Right-click the tool and select Batch. If the Batch command is disabled the tool does not support batch mode.
After selecting the Batch mode, a page opens in the Geoprocessing pane for you to define various options for the batch geoprocessing tool.
- Choose which of the parameters of the selected tool which will drive the batch process—the batch parameter. The batch parameter is designated to accept multiple datasets or values as input. The batch tool will run once for each of the datasets or values you provide as input to the batch parameter.
The batch parameter choicelist only includes the tool's input parameters. The first input parameter is selected by default.
Consider the following example of a tool that has two input parameters: Input Dataset and Distance. If you select the parameter Input Dataset as the batch parameter, you can specify multiple input datasets and the batch tool will run once for each input dataset, using the same distance for each input dataset. If you select the parameter Distance as the batch parameter, you can specify multiple distances and the batch tool will run once for each distance, using the same input dataset each time.
- Choose if the batch tool should be temporary or saved. If you choose to save it, you can specify the new batch tool name and the toolbox where it will be saved.
- Choose whether the batch tool should Add output datasets to an open map. If you wish to run a large batch with many iterations, you can uncheck this option so that a large number of layers are not added to the map.
- Click Next.
After completing the steps above, a batch version of the geoprocessing tool will open in the Geoprocessing pane, where you can specify the tool parameters and run it.
Run a batch tool
The parameters displayed on the batch tool will closely match the normal version of the tool. One important difference is that the parameter you selected as the batch parameter will now have a Batch prefix on the parameter label and will support specifying multiple values. Each value that you enter for this batch parameter will result in an additional iteration of the tool to run within the batch.
For example, to add a field with the same name to several datasets, perform the following steps:
- Right-click the Add Field tool and select Batch.
- Select Input Table as the batch parameter and click Next.
The Batch Add Field tool will open.
- For the Batch Input Table parameter, browse to and select any dataset which should have the new field added.
- Enter the new field name, type, and any other desired parameter settings.
- Run the Batch Add Field tool.
Dynamic output naming
Most geoprocessing tools create an output dataset. When running a tool in batch mode, the naming of the tool's output datasets must receive special consideration so that a unique name is used for every iteration of the batch tool.
Batch tool outputs are dynamically named using the %Name% variable in output parameters. The %Name% variable is automatically included in every output dataset parameter. It can be manually added to other parameters that should use dynamic naming.
The %Name% variable is replaced by the value in the batch parameter during each iteration. If the value in the batch parameter contains spaces or special characters, they are replaced with an underscore. If the value is a path to a dataset, only the dataset name is used.
If you do not use the %Name% variable in the output dataset path, the same dataset path will be used for each iteration, resulting in each iteration overwriting the output of the previous iteration. This does not apply to tools that update or modify the input dataset.
For example, if a batch tool's output is set to %Name%_stats, and the Batch Input Table parameter contains tables named City, County, and State, the batch tool will create three outputs, each named after one of the inputs: City_stats, County_stats, and State_stats.
The following additional variables may be useful in dynamically specifying a parameter value. They can be used similarly to the %Name% variable.
- %Workspace Name%—The workspace or folder name of the data in the batch parameter.
- %Path%—The catalog location of the data in the batch parameter, not including the data name or extension.
- %Extension%—The extension of the data in the batch parameter.
These variables are defined in the batch model tool using in-line variable substitution.
Add additional tools to the batch
Since the batch tools you use are model tools, they can be extended with additional tools to perform a chain of processing steps. If you want to extend your batch model, you must select the Save the batch tool option when creating the batch tool, so the model is saved in a location where you can find and edit it.
For example, if you started by opening the Add Field tool in batch mode, you may want to extend the Batch Add Field model with the Calculate Field tool so the model first adds a field to a number of datasets, then calculates the values in that field.