Is This Content Helpful?
We're glad to know this article was helpful.
This article provides a procedure to repeat run a model by calling the model from Python within a loop and pass arguments to it. It is one of two methods available to create batch style processes so that geoprocessing models can be repeated.
Another method of batching geoprocessing tasks is to create a model of the basic task, export that to a script and then add Python code to perform looping. See the link in the Related Information section for more information on this method.
While the geoprocessing environment of ArcGIS 9.x supports Python, VBScript, JScript, and Perl scripting languages,any scripting language that is COM compliant can be used to create successful geoprocessing scripts.
The code example below uses the example model called 'MyClipTool'. It resides in a toolbox called 'MyToolbox'. MyClipTool has two arguments: an input shapefile and an output shapefile. The script loops through each file in 'C:\mydata\input_folder\'. For each iteration of the loop, it executes MyClipTool passing in an input shapefile and writing the output to 'C:\mydata\output_folder\'.
# Import system modules
import sys, string, os, win32com.client
# Create the Geoprocessor object
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
# Load required toolboxes...
gp.overwriteoutput = 1
gp.workspace = "C:\\mydata\\input_folder\\"
outfolder = "C:\\mydata\\output_folder\\"
fcs = gp.ListFeatureClasses()
fc = fcs.Next()
gp.MyClipTool(fc, outfolder + fc)
fc = fcs.Next()
For more information on getting started with writing geoprocessing scripts, see the 'Writing Geoprocessing Scripts' white paper. It is available on the ESRI Library CD and is entitled Writing_Geoprocessing_Scripts.pdf.