Run a model as a Windows scheduled task


Instructions provided describe how to call a custom model from Python and run it as a Windows scheduled task.

Another method for automating the geoprocessing tasks contained in a custom model is to export the model to a script. However, it is suggested that there is some knowledge of the scripting language, as some edits may need to be made to the exported script.

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.

While tracing through the script below, there are a number of important things to note.

· The desktop license to be used must be retrieved by the script and available at the time when the script will be executed.


object.SetProduct(productCode As String) As String



· If the model uses any extension tools, the extension license to be used must be retrieved by the script and available at the time when the script will be executed.


object.CheckOutExtension(extensionCode As String) As String



· The toolbox that contains the model must be added to the script. The toolbox can be referenced either by specifying its path or by specifying its unique alias.


object.AddToolbox(Toolbox As String)

Example 1

gp.Workspace = "c:/mytoolboxes"

Example 2


· If the model is dependent upon specific environment settings they must be declared within the script. Environment settings can be loaded from an environment settings file (text stored in an XML schema). Environment settings can also be defined individually.


object.LoadSettings(XMLFile As String)

Example 1

gp.LoadSettings = "c:/temp/mysettings.xml"

Example 2

gp.QualifiedFieldNames = "UNQUALIFIED"

· Script-based tools do not derive general Geoprocessing options like 'Overwrite the outputs of geoprocessing operations'.


object.OverwriteOutput = variable(Boolean)


gp.OverwriteOutput = 1


The code example below uses two models: one called 'NoParameterTool' and one called 'ParameterTool'. Both models reside in a toolbox called 'MyToolbox'.

'NoParameterTool' had all of the arguments supplied when building the model and does not need any additional information from the user at run-time.

'ParameterTool' has two arguments that must be supplied at run-time: an input shapefile and an output shapefile.
# Import system modules...
import arcgisscripting, sys, string, os

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

# Set the License...

# Not required if the model does not use any extension tools

# Load environment settings if necessary...
gp.LoadSettings = "c:/temp/mysettings.xml"

# Load required toolboxes...

gp.OverwriteOutput = 1

# All arguments were supplied to model prior to saving

# Two arguments are supplied at run-time
gp.ParameterTool_MyToolbox("c:/myData/InputData.shp", "c:/myData/OutputData.shp")

The script can now be executed as a scheduled task. See the link in the Related Information for 'Schedule a geoprocessing script to run at prescribed times'.

    Article ID:000009370

    • ArcMap 9 x

    Get help from ArcGIS experts

    Contact technical support

    Download the Esri Support App

    Go to download options