An example model that uses the Hillshade tool from 3D Analyst extension, similar to the example in blog Part 1. This example shows only a part of a larger workflow and can be extended as required.

The model is created for sharing, but it requires the 3D Analyst extension which might not be available with all those the model is shared with. To account for such a case a simple “if” script tool is added to check the availability of the extension. If the extension is not available, the model uses a custom messaging tool to inform the user about the unavailability of the license and that the model cannot be run.

Illustration 1- Does Extension Exists model

The Does Extension Exist? script tool uses the CheckExtension Acrpy function to check the availability of the extension and the CheckOutExtension function to check out the extension for use.

To make this script tool a generic tool that can be used to check the availability of any extension, a value list filter is set on the Extension to Check parameter from the script tool properties as shown below.

Illustration 3- Does Extension Exists value list parameter

The list that appears in the drop down list on the tool dialog are the actual names of the extensions available with ArcGIS such as, 3D Analyst, Business Analyst, etc. However, these extensions have a code name that is used to look up the extension license by the script tool. To account for this difference in the name that appears on the tool dialog and the name code that is used in the ArcGIS system, the script tool uses a list of if-then-else statements as shown below.

Illustration 4- Handling extension names and their codes in the script

Adding and connecting the script tool to other tools in ModelBuilder

Setting precondition

The Exists Boolean parameter is set as a precondition to the Hillshade tool. This ensures that the Hillshade tool will run only if the Exists Boolean parameter is True. The Does not Exist Boolean parameter is connected as a precondition to another script tool that adds a custom warning if the extension is not available. This custom script tool can be created easily with just three lines of code as shown below:

Illustration 5- Simple Add Warning script tool

To create a more generic tool that can add an error, a message or a warning see the Add Error, Message or a Warning script tool with the download. This tool has three optional input parameters, one each for a custom error, a message or a warning. The script uses if-then-else statements to check which input parameter has a value and based on that creates an appropriate output.

Illustration 6- Generic Add Error, Message or Warning script tool

Any inline variable can be used as an input to this script tool parameters. For example to add an error using the name of the extension that the user of this tool has selected from the drop down list the variable Extension to Check is used as inline variable as shown below:

Illustration 7- Using inline variable substitution in the error message

There is nothing like one is better than the other. It’s more of a preference thing. If you are more comfortable with Python, that is the way to go. You can do almost all the things using a script.

It is more or an organizational matter i.e. “How can I organize my workflow more efficiently?”. If you are doing higher level logical processing or a number of logical processing things, then script is the way to go. You would not want to add 3 or 4 script tools in a model with 5 tools.

If you are not very comfortable with Python/scripting ModelBuilder and its visual elements are good for you. For the things you cannot do with tools in ModelBuilder you can use small snippets of Python, thus limiting your frustration with understanding too much code.

With ArcGIS 10 iterators have made the batch processing/looping very easy to use and understand, visualize and control.