Specifying tool inputs and outputs

Almost all geoprocessing tools take datasets as input and produce new datasets. When using geoprocessing tools, the one thing you want to avoid is typing in long dataset names, like:


Entering such a long dataset name is tedious, frustrating, and error-prone. That's why geoprocessing allows you to drag and drop datasets or layers onto a tool parameter, use the Browse button (Browse) to navigate to a dataset, or select a layer from a drop-down list.

Additionally, there are two features designed to make specifying input and outputs datasets much easier; the current and scratch workspace environment settings.

Current workspace

The key idea behind the current workspace is that you set a workspace once and then use only the base name when entering input and output pathnames. Borrowing from the example above, you would set your current workspace to:


Once set, you can enter the base name of the dataset in the parameter. For example, you could enter


for an input (or output) parameter, and it will be expanded to


Scratch workspace

The scratch workspace is meant to contain temporary data. Scratch workspace is used by model tools to write intermediate data. You need to set the scratch workspace environment only when using ModelBuilder.

Workspace and base name

Before getting started using current and scratch workspace, some definitions are in order. The first are catalog path, pathname, location, and dataset name. In practical terms, they all mean the same thing—the string used to specify a dataset, as illustrated below. In this discussion, we'll use dataset name.

A dataset name has two components, the workspace and the base name, also shown below.

Dataset name

Setting the current workspace

The steps below demonstrate specifying and using current workspace. The data used is D:\ArcTutor\BuildingaGeodatabase\Montgomery.gdb, which is part of the tutorial data installed with ArcGIS. (The location of this tutorial data is specified when you install ArcGIS tutorial data.) The contents of Montgomery.gdb are as follows:

Contents of Montgomery.gdb

  1. Start ArcCatalog or ArcMap and expose the ArcToolbox window by clicking Show/Hide ArcToolbox (Show/Hide ArcToolbox Window).
  2. In the ArcToolbox window, right-click on the ArcToolbox entry and click Environments, as shown below.
  3. Accessing environment settings

    There are several other methods to set environments, and you can set environments so that they apply for all tools, for the execution of one tool, for a model, a model process, or a script.

    Learn more about environment settings

  4. Expand the General Settings category, as shown below.
  5. Expanding the General Settings category

  6. In the Current Workspace parameter, enter the path to the workspace. As shown below, the workspace is D:\ArcTutor\BuildingaGeodatabase\Montgomery.gdb\Landbase, a feature dataset within the geodatabase.
  7. Setting the Current Workspace

    You can specify any valid workspace, such as a system folder containing shapefiles, a file geodatabase, a coverage workspace, or a connection to an ArcSDE workspace. As shown above, a workspace can be a feature dataset within a geodatabase.

  8. Click OK.

Using a base name

Once the workspace has been set, you can enter just the base name whenever a dataset name is needed. The following steps demonstrate this.

  1. Open the Clip tool. Clip is found in the Analysis Tools toolbox under the Extract toolset. Alternatively, you can open any tool with a feature class as input.
  2. In the Input Features parameter, enter "Blocks", the base name of a feature class in the current workspace. After entering the base name, click the mouse anywhere else in the dialog box. This causes the dialog to refresh. Two things happen on refresh, as shown in the illustration below:
    • The base name (Blocks) is joined with the current workspace to form the dataset name (D:\ArcTutor\BuildingaGeodatabase\Montgomery.gdb\Landbase\Blocks). The Input Features parameter is then replaced with this dataset name.
    • A unique output dataset name is auto-generated. The base name is the same as the input base name (Blocks) appended with an underscore and the name of the tool (Clip), and, if necessary to ensure a unique name, a number.

    Entering a base name for the input

  3. If you want to replace the auto-generated output name, you can input a base name, and it will be expanded to a dataset name, as shown below.
  4. Using base name for an output dataset

After you've run a tool, you may find that output isn't written where you expect— perhaps you made a mistake when entering the output name, or you've just forgotten where it was written. If this is the case, go to the Results tab. The Results tab contains records of all tools that you've run along with their inputs and output datasets.

Displaying the current workspace in a tool dialog

You can hold the mouse over the Browse button (Open or Browse) for a moment, and the current workspace will be displayed, as shown below.

Displaying the current workspace in a tool dialog

When you click the Browse button, the Browse dialog box will open in the current workspace.

Current workspace in command line and scripting

In the command line window, the workspace command sets the current workspace. After setting the workspace, you can use the base name of any dataset within the workspace, as illustrated below.

Using the workspace command

Following is a Python script example that shows use of the workspace command.

# Purpose: Determine the type of vegetation within 100 meters of all stream crossings

# Create the Geoprocessor object
import arcgisscripting
gp = arcgisscripting.create()

    # Set the workspace (to avoid having to type in the full path to the data every time)
    gp.Workspace = "c:/projects/RedRiverBasin/data.mdb"

    # Process: Find all stream crossings (points)
    gp.Intersect("roads ; streams ", "stream_crossings", "#", 1.5, "point")

    # Process: Buffer all stream crossings by 100 meters
    gp.Buffer("stream_crossings","stream_crossings_100m", "100 meters")

    # Process: Clip the vegetation feature class to stream_crossing_100m
    gp.Clip_analysis("vegetation", "stream_crossings_100m", "veg_within_100m_of_crossings")

    # Process: Summarize how much (area) of each type of vegetation is found within 100 meters of the stream crossings
    gp.Statistics("veg_within_100m_of_crossings", "veg_within_100m_of_crossings_stats","shape_area sum","veg_type")

    # If an error occurred while running a tool print the messages
    print gp.GetMessages()

Using current workspace in the batch grid

You can use a base name in the batch grid, as shown below.

Using current workspace with the batch grid

Learn more about batch processing

The scratch workspace environment

In addition to the Current Workspace, there is the Scratch Workspace environment. You set it just like the Current Workspace.

Scratch workspace environment

The primary purpose for the scratch workspace environment is for use by ModelBuilder. ModelBuilder needs a workspace to write intermediate datasets—datasets that are of no use once a model is run.

NOTE: Because the scratch workspace is meant for temporary data, do not set it to an ArcSDE geodatabase. This could cause performance problems—you'll be writing temporary scratch data to an enterprise database. It's suggested that you always use a file geodatabase (rather than a personal geodatabase or a shapefile workspace) for the scratch workspace.

If you set the scratch workspace environment, tools will use it to auto-generate output dataset names, as shown below.

Example of auto-generated output using scratch workspace

NOTE: If you enter a base name for an output, the current workspace is used to construct the dataset name, not the scratch workspace, as shown below.

Using base name with scratch workspace

The rule is that anytime a base name is used, it is joined with the current workspace. Be aware of this when writing scripts. In the code snippet below, the output dataset, "stream_crossings", will be written to the current workspace, not the scratch workspace.

    gp.Workspace = "c:/projects/RedRiverBasin/data.mdb"
    gp.scratchWorkspace = "c:/projects/Scratch/scratch.gdb"
    gp.Intersect("roads ; streams ", "stream_crossings", "#", 1.5, "point")

Although you are allowed to set the scratch workspace within a script, there is no reason to do so.

In the Command Line window, you can set the scratch workspace using the scratchWorkspace command.

Auto-generated output dataset names

All tools automatically create an output dataset name for you. The logic for generating the output name is as follows:

See Also