HOW TO

Run a model as a Windows scheduled task

Last Published: April 25, 2020

Summary

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.

Syntax

object.SetProduct(productCode As String) As String

Example

gp.SetProduct("ArcView")



· 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.

Syntax

object.CheckOutExtension(extensionCode As String) As String

Example

gp.CheckOutExtension("spatial")



· 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.

Syntax

object.AddToolbox(Toolbox As String)

Example 1

gp.Workspace = "c:/mytoolboxes"
gp.AddToolbox("custom_tools.tbx")

Example 2

gp.addtoolbox("c:/mytoolboxes/custom_tools.tbx")



· 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.

Syntax

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'.

Syntax

object.OverwriteOutput = variable(Boolean)

Example

gp.OverwriteOutput = 1

Procedure

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.
Code:
# Import system modules...
import arcgisscripting, sys, string, os

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

# Set the License...
gp.SetProduct("ArcView")

# Not required if the model does not use any extension tools
gp.CheckOutExtension("spatial")

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

# Load required toolboxes...
gp.AddToolbox("c:/mytoolboxes/MyToolbox.tbx")

gp.OverwriteOutput = 1

# All arguments were supplied to model prior to saving
gp.NoParameterTool_MyToolbox()

# 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

    Software:
    • ArcMap 9 x

    Receive notifications and find solutions for new or common issues

    Get summarized answers and video solutions from our new AI chatbot.

    Download the Esri Support App

    Get help from ArcGIS experts

    Contact technical support

    Download the Esri Support App

    Go to download options