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.
Syntaxobject.SetProduct(productCode As String) As StringExample 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.
Syntaxobject.CheckOutExtension(extensionCode As String) As StringExamplegp.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.
Syntaxobject.AddToolbox(Toolbox As String)Example 1gp.Workspace = "c:/mytoolboxes"
· 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.
Syntaxobject.LoadSettings(XMLFile As String)Example 1gp.LoadSettings = "c:/temp/mysettings.xml"Example 2gp.QualifiedFieldNames = "UNQUALIFIED"
· Script-based tools do not derive general Geoprocessing options like 'Overwrite the outputs of geoprocessing operations'.
Syntaxobject.OverwriteOutput = variable(Boolean)Examplegp.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
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'.