I have been doing some testing with models that I want to schedule and to start with I created a basic model that only creates a feature class within one of my file geodatabases.
My toolbox name is: CDWGeocoding
The alias name is: CDWGeo
Model name: ImportTest
This model has no parameters.
I've been running the following script (which completes just fine). The problem is the feature class is not being created. This runs fine with ArcGIS just not when running through a script.
import arcpy
import os
from datetime import datetime
print("Starting toolbox import.....")
arcpy.ImportToolbox(r"C:\Users\JOEBOBSMITH\Documents\ArcGIS\CDWGeocoding.tbx")
print("Import Complete")
print("Model executing.....")
try:
#CDWGeo is the toolbox alias
arcpy.ImportTest_CDWGeo
print("Model complete.")
except:
print arcy.GetMessages(2)
I've been using this page as a reference:
Scheduling a Python script or model to run at a prescribed time | ArcGIS Blog
Does anyone see any problems with this script? It seems pretty straight forward and simple. I'm sure it's something simple that I am missing. Thanks!
Solved! Go to Solution.
You are calling your function as a property of arcpy, not a function (not sure why it doesn't give an error, but it's not doing what you think it's doing). It should be:
arcpy.ImportTest_CDWGeo()
It's hard to tell without seeing the model or the toolbox, but is it printing all the messages? What about the final GetMessage?
All messages are being printed.
I can post an image of the model shortly. It's just the one tool to create the feature class. Very basic.
Here is the model in questions:
Properties of create feature class:
I'm wondering if the feature class is being created, but not where you expect it to. I think you need to set the workspace in the python script.
I tried adding this piece of code but the results are still the same:
#Set workspace
uri = r"C:\Users\JOEBOBSMITH\Documents\ArcGIS\PDADEV.gdb"
arcpy.env.workspace = uri
You are calling your function as a property of arcpy, not a function (not sure why it doesn't give an error, but it's not doing what you think it's doing). It should be:
arcpy.ImportTest_CDWGeo()
Sometimes it takes a village! Thank you. Working perfectly now.
It doesn't give an error because if you enter a function without the () Python will simply return the text representation of the object "arcpy.method". (The method has been imported, so it exists, so no error.)