Launching model with Python

5370
10
Jump to solution
05-07-2015 10:50 AM
AnthonyBarron
New Contributor III

Hello,

I'm new to using arcpy and I'm running into a few complications in getting a batch job within a model to launch automatically using a python script. I've created the model, tested it, and it works perfectly. However, when I try to launch the model from python, it does not work. I've tried two methods. I've attached relevant documents.

1) Model_ExecuteModelV5.py contains the script used to import the toolbox, and run the model. (the model has no parameters). I've tested the script and I get the printed "Complete". However when I look at my results, the model did not run properly. In this case it did not identify any QC errors which the batch file in the model should have identified. Again, when I test the model within ArcGIS Desktop or Catalog, it works.

2) Model_ExecuteModelV7.py contains the script with the exported model. I exported the model to a .py file and tested that within python. As a result I received an error saying:

AttributeError: 'module' object has no attribute 'ExecuteReviewerBatchJob_Reviewer'

Any support would be greatly appreciated.

0 Kudos
1 Solution

Accepted Solutions
IanMurray
Frequent Contributor

Hi Anthony

for the ExecuteModelV5, make sure Model is the Alias of your Model.

for the ExecuteModelV7, I think the string for the extension you are checking out, it needs to be all lower case per examples  ArcGIS Help (10.2, 10.2.1, and 10.2.2)

arcpy.CheckOutExtension("datareviewer")

case matters greatly in python

Edit: Edit was made for a correction

View solution in original post

10 Replies
IanMurray
Frequent Contributor

Hi Anthony

for the ExecuteModelV5, make sure Model is the Alias of your Model.

for the ExecuteModelV7, I think the string for the extension you are checking out, it needs to be all lower case per examples  ArcGIS Help (10.2, 10.2.1, and 10.2.2)

arcpy.CheckOutExtension("datareviewer")

case matters greatly in python

Edit: Edit was made for a correction

AnthonyBarron
New Contributor III

Ian,

Thank you for the recommendations and references. I've had a chance to modify everything but with no luck. I don't know if this makes any difference but I am using C:\Python27\ArcGISx6410.2\python.exe to run this script.

For ExecuteModelV5, I renamed the toolbox (ToolboxModel.tbx), the toolbox alias (ToolboxModel), and the model (BatchModel). I included the closed parentheses and received a larger error. And of course, when I tried to do it without the closed parentheses, the script would run with no issues, but the model would not execute properly.

For ExecuteModelV7, I tried running the batch job with all recommendations and used the examples from ArcGIS Help (10.2, 10.2.1, and 10.2.2) I still get the following error.

Traceback (most recent call last):

  File "//coacd.org/gis/911_Addressing/Addressing/addr_group_backup/PROJECTS/DataQC_Automation/Anthony/DataReviewerClass/Model_ExecuteModelV11.py", line 26, in <module>

    arcpy.ExecuteReviewerBatchJob_Reviewer(reviewer_db, session, AddressingQC_V17_rbj, production_db)

AttributeError: 'module' object has no attribute 'ExecuteReviewerBatchJob_Reviewer'

0 Kudos
AnthonyBarron
New Contributor III

Ian,

Ok getting a little closer to a solution. I'm going back to just basically trying to get the batch file to run through python. I used the Python CMD line to get more details. It looks like my reviewer workspace and the "ExecuteReviewerBatchJob" parameters may be input incorrectly. But my Batch job parameters were input exactly as shown on the ArcGIS help document. I'll keep you posted on what I find. but if you have any additional recommendations, please send them my way. Thanks.

0 Kudos
curtvprice
MVP Esteemed Contributor

Screenshots tend to cut things off.

Posting Code blocks in the new GeoNet

It looks like my reviewer workspace and the "ExecuteReviewerBatchJob" parameters may be input incorrectly. But my Batch job parameters were input exactly as shown on the ArcGIS help document.

When faced with a complex set of parameters I often will run the tool interactively from a dialog. This gives you access to the help on every parameters as you enter it, instead of trying to interpret a code block in the help on its own.

Once I get the tool to run that way, from the Results window I can right click / Copy As Python Snippet and paste into code and edit away. This has really helped me when faced with difficult keywords and complex parameters.

IanMurray
Frequent Contributor

this topic is cross-posted here

SepheFox
Frequent Contributor

Anthony, since your question was answered in the cross-post, you should probably mark this one as answered too.

AnthonyBarron
New Contributor III

Alright So I have both scripts executing correctly now. One for the Data Reviewer Batch Job and the other for the model. I used the following solutions..

1) I changed all of the single backslashes to double backslashes in all filepaths.

2) I deleted Python IDLE 64-bit and manually executed the script in Python 32-bit

3) I skipped the Parameter "AOI" in the "arcpy.ExecuteReviewerBatchJob_Reviewer()" Function. As a result, Python was reading the parameter "ALL_FEATURES" as my AOI.. Which is invalid.

After completing those three changes everything works like a charm without issues. Thank you for all of the support across the board.

0 Kudos
lelaharrington
New Contributor III

anthony i am running into the same issues however i am not running this in a scheduler. i have 4 models that i am trying to get to run ( one at a time) thru python.

basically run script 1

if script 1 successful run script 2

and so on. i have log lines in there to tell me at the end if this was successful. but i keet getting errors

am i missing something?

import arcpy, time, os, sys

Date = time.strftime("%m-%d-%Y", time.localtime())

Time = time.strftime ("%I:%M:%S :p",time.localtime())

LogFile = file(r"F:\\GIS\\Python_Scripts\\Logs\\GLE to BIS PROJECTION AND TRANSFER_" + Date + ".txt", 'w')

output = open(r"F:\\GIS\\Python_Scripts\\Logs\\GLE to BIS PROJECTION AND TRANSFER_" + Date + ".txt", 'w')

arcpy.ImportToolbox("F:\\GIS\\Python_Scripts\\GLE_BIS_Silverlight_Overwrite\\GLE_BIS.tbx")

# Local variables:

output.write("Script Started At: " + str(Date) + " " + str(Time) + "." + "\n" + "Start Delete Process" +"\n")

# Process: Delete Temp Holding Shapefiles

arcpy.DeleteTempHolding_GLE_BIS()

arcpy.ExecuteDeleteTempHolding_GLE_BIS()

try:

     # Process: Delete Temp Holding Shapefiles

        if arcpy.ExecuteDeleteTempHolding_GLE_BIS():

            output.write("Delete of Temporary files SUCCESS","\n")

except:

    output.write("Delete of Temporary files FAIL","\n")

output.write("END OF SCRIPT","\n")

# reset date and time from when  started

lDate = time.strftime("%m-%d-%Y", time.localtime())

lTime = time.strftime("%I:%M:%S %p",time.localtime())

# write to log and close

output.write(str("GLE to BIS Script Ended at  " + str(lDate) + " " + str(lTime) + "." + "\n"))

output.close()

now = time.time()

print "Script Complete"

0 Kudos
AnthonyBarron
New Contributor III

Do you have a copy of the error messages?

0 Kudos