A quick tour of executing tools
There are a number of ways you can execute tools. The most common method is to open the tool dialog box, fill in its parameters, and click OK to execute the tool. For system tools, tool execution occurs in the background, meaning that you can continue working in ArcMap while the tool executes. You will receive a notification message when the tool finishes, and you can view information about the tool's execution in the Results window. Normally, outputs created by tools are automatically added to the ArcMap table of contents.
To execute a tool, you must first locate the tool by searching for it in the Search window or browsing to it in the Catalog window.
Executing tools using the tool dialog box
To open a tool dialog box in the Search window, click the tool name.
To open a tool dialog box in the Catalog or ArcToolbox window, double-click the tool or right-click and choose Open.
After the tool dialog box opens, you fill in the tool's parameters. Each tool has its own unique set of parameters. Some parameters are required—they must be filled in (that is, they must have values) for the tool to execute. Other parameters are optional, meaning you can leave them blank or accept their default values. Tools have both input and output parameters. Input parameters are typically existing datasets or options that control what the tool does. Output parameters are usually new datasets created by the tool. For output dataset parameters, an output dataset name and location are automatically created for you after you have entered one or more input parameters.
Executing tools using ModelBuilder
ModelBuilder is a powerful application that allows you to string together a sequence of tools, using the output of one tool as the input to another tool, as illustrated below.
In ModelBuilder, you add a tool, open its dialog box, fill in parameters, then click the OK button. The tool does not execute when you click OK—you have to run the model for the tool to execute. This allows you to string together multiple tools and execute them all at once.
Models are how you automate your work. When you create a model, you are preserving a data processing workflow that you can execute multiple times using different input data. There are an infinite number of tasks you can automate using models.
Executing tools using the Python window
Tools can also be executed in a text-based programming language such as Python. Since Python is text based (rather than a visual programming language like ModelBuilder), you type the tool name followed by its parameters. The Python window, illustrated below, is where you can enter Python code and execute it immediately.
Although this may seem like extra work compared to using the tool dialog box (who wants to type a bunch of stuff?), there are advantages to using Python and the Python window:
- You can use logic, such as if-then-else for conditional execution or for loops to iterate over sets of data, and access Python data structures such as dictionaries and lists.
- You can access functionality in standard Python modules for string, math, or file and folder manipulation. In the illustration below, the glob module is used to navigate through files in a system folder.
- Python has a rich third-party base of modules that can be used to manipulate and transform data.
- When you load the ArcPy site-package (loaded with the import statement in the illustration below), you can access all geoprocessing tools and a host of other functions for reading features row by row, describing data, or interacting with ArcMap. For example, in the illustration below, the ArcPy mapping module is used to add layers to the current map.
Python code that executes a geoprocessing tool is sometimes referred to as a command. Prior to ArcGIS 10, there was the Command Line window where you could execute geoprocessing tools by entering text (you couldn't use Python). The text you entered was called a command. In ArcGIS 10, the Python window replaced the Command Line window, but the term command has stayed around—you may occasionally find it in documentation. A command is equivalent to executing a geoprocessing tool function in Python.
Executing tools within Python scripts
The Python window is where you enter code and execute it immediately. But you can also use a text editor or an integrated development environment (IDE) such as PythonWin to create Python files on disk (files with a .py extension). These files, known as scripts, are programs you can execute from either the operating system prompt or by creating a script tool that executes the script. A script tool is just like any other geoprocessing tool--you can execute it using its dialog box, within models, in the Python window, or in Python scripts.
Environments affect tool execution
Environment settings can be thought of as additional parameters that affect the execution of a tool. Environments differ from normal tool parameters in that they do not appear on a tool's dialog box or Python usage (with certain exceptions) but are set using a separate dialog box or function. Environment settings can significantly affect tool execution. For example, you can set the Extent environment so that only the features in the current map extent are used in tool execution. You can set the Output Coordinate System environment so that your tool writes its output features in a different coordinate system from the input features.