- Make all your intermediate data variables Managed data variables.
- Set the scratch workspace environment to an existing file geodatabase.
- In the ArcToolbox window, right-click the model tool and click Edit. This opens ModelBuilder.
- In ModelBuilder, right-click on all intermediate data variables and choose Managed, as illustrated below. After choosing Managed, a check will appear next to Managed (just like Intermediate in the illustration below).
- Save and close the model.
- In the ArcToolbox window, right-click the ArcToolbox entry and click Environments.
- In the Environment Settings dialog box, expand General Settings.
- In the Scratch Workspace setting, enter the pathname to a file geodatabase.
- Click OK.
- Execute your model by double-clicking the model tool in the ArcToolbox window, entering parameters, and clicking OK. If there are still errors, follow the above steps again, double-checking that you've made all intermediate data variables managed and that the scratch workspace is set properly. If there are still problems, then either:
- the problem is not with intermediate data, or
- the scratch workspace environment is being reset by the model. Check the model environment settings as follows.
- In the ArcToolbox window, right-click your model tool and click Properties.
- In the properties dialog box, click the Environments tab.
- If the check box next to General Settings is checked, click Values.
- In the Environment Settings dialog box, expand General Settings.
- If Scratch Workspace environment setting contains a pathname to a workspace, check that the workspace exists. (You can check existence by clicking Browse and browsing to the location). If the workspace doesn't exist, enter the pathname to an existing workspace.
- how output pathnames are auto-generated
- how ModelBuilder keeps track of whether you have altered any data variable
- how the Managed option can be used for intermediate data
- how you can use variable substitution for output pathnames
- how ArcGIS server overrides the scratch workspace environment
- how the ToolShare folder structure is designed to help you manage intermediate data
- how scratch data can be written to the in_memory workspace
- how scratch workspace environments are used in scripting
How output pathnames are auto-generatedWhen you open a tool from ArcToolbox or inside ModelBuilder and provide input datasets, the location of the output data is automatically generated. This auto-generated name is constructed using the following logic (details can be found in Specifying tool inputs and outputs):
- The location in the Scratch Workspace environment variable. If this variable is blank, then
- the location of the Current Workspace environment variable. If this variable is blank, then
- the location of the first project data you add to the tool. If this location is read-only, then
- your system temp directory.
The altered state of data variablesWhenever you modify the value of a variable within ModelBuilder, it is considered altered. Once a variable is altered, ArcGIS must assume that you want to use the altered value and will never again modify it. If the altered variable contains a pathname containing folders or workspaces that do not exist on another user's computer, the model will fail. If the variable is an output dataset, and its value is empty or unaltered, geoprocessing tools will auto-generate a pathname. You want to take advantage of this fact and leave output dataset parameters unaltered so that geoprocessing will auto-generate a pathname for you.In ModelBuilder, there is no way for you to determine if a data variable is considered altered, but you can reset the altered state of a variable by deleting (blanking out) the existing value and then validating the entire model. Validation will then see that the output value is blank and will auto-generate a new name for intermediate data, and then mark the data variable as unaltered. A better method, however, is to set the variable to Managed, as described next.
Using Managed dataYou may choose to have ModelBuilder manage the location of intermediate data (using the logic described above). You can set a data variable to be managed by right-clicking the variable and clicking the Managed option. Once you've set a variable to Managed, you cannot change the output path within ModelBuilder (the parameter control will always be disabled). This means that Managed data cannot have its altered status changed and will have a new auto-generated pathname for the data each time the model executes.Learn more about managed data
Using %scratchworkspace%Non-system script tools may or may not provide an auto-generated output pathname. If they don't provide an auto-generated output pathname, you can use variable substitution in your output pathnames, as shown below. Learn more about variable substitutionLearn more about providing an auto-generated output pathname for your script tools The main issue with using variable substitution is that you rarely know if %scratchworkspace% will be a system folder or a geodatabase when the tool is executed. If, when you built your model in ModelBuilder, your scratch workspace was a shapefile workspace (a folder), ModelBuilder would have automatically appended ".shp" to the feature dataset name (that is, you entered "%scratchworkspace%/temp" and ModelBuilder automatically replaced it with "%scratchworkspace%/temp.shp"). At a later time, you change your scratch workspace to a file geodatabase then run the model tool from the ArcToolbox window. The model fails because it is trying to write "temp.shp" to the file geodatase, and geodatabases cannot contain special characters, such as the dot found in ".shp". There are only two cases where you can safely predict the type of scratch workspace:
- When the tool is running on an ArcGIS Server.
- If you use the recommended ToolShare folder structure which contains a scratch folder.
ArcGIS Server scratch workspacesWhen a server tool is executed on the server, ArcGIS Server creates a unique job folder for the tool to use. Inside this job folder is a folder named scratch, and within this folder is a file geodatabase named scratch.gdb, as shown below. ArcGIS Server sets the application level scratch workspace environment to the location of this unique scratch folder. It does not change the tool, model, or model process level settings. When the server tool is run, the location of any intermediate or managed output data variable will be reset, unless
- the data variable is not Managed and has been altered or
- the tool, model, or model process scratch workspace environment has been set.
Using the share folder structureA structure for sharing tools described a recommended folder structure, called the ToolShare folder, shown below. This ToolShare folder structure works well for sharing tools, whether you are packaging and shipping, sharing on a LAN, or publishing to an ArcGIS Server. Note that like the unique job folder created by ArcGIS Server, the ToolShare folder contains a scratch folder and a scratch.gdb. You can set up your models so that its intermediate data is always written to this scratch folder, as follows:
- Set the model environment scratch workspace to the scratch folder within the share folder. Learn more about specifying model environment settings
- Set the toolbox to use relative pathnames. Learn more about setting relative pathnames for a toolbox
- In your model, use variable substitution for any intermediate data.
Using %scratchworkspace% in a model parameter will take the application level scratch workspace, not the model level scratch workspace, so you only want to use this technique for non-parameter data variables, such as intermediate data. If you use this technique when sharing your toolbox across a LAN, any execution of your tools will write intermediate data to this scratch folder. Using the following configuration as an example:
- A user on \\pondermatic adds a connection to your share folder \\cogitator\GPTools.
- They then add the \\cogitator\GPTools\RetailFunctions to their ArcToolbox.
- They open and execute a tool within the RetailFunctions toolbox.
- Since you stored the RetailFunctions toolbox with relative pathnames, the location of the scratch workspace, %scratchworkspace%, expands to \\cogitator\GPTools\scratch, and all intermediate data is written to \\cogitator\GPTools\Scratch.
Writing scratch data to the in_memory workspaceGeoprocessing provides an in-memory workspace where you can write features and tables. Learn more about the in_memory workspace
NOTE: Only tables and feature classes (points, lines, polygons) can be written to the in_memory workspace. The in_memory workspace does not support extended geodatabase elements such as subtypes, domains, representations, topologies, geometric networks and network datasets. Only simple features and tables can be written.
NOTE: Do not set your scratch workspace environment to the in_memory workspace. Use in_memory only for outputs that you know to be simple features and tables.