Running a model with py script errors

1593
5
Jump to solution
08-21-2019 12:06 PM
DavidMaack
New Contributor

Hello everyone, I am trying to automate a model I have built in Arcpro. I have looked at other posts with similar issues, but can't seem to fix it or figure out what I'm doing wrong. Please help

The model takes a CSV, creates points (customers) then draws a line from point to point according to the matching xy in each customer. It also creates another point file with another CSV file. Heres what it looks like: 

Using online resouces I created a script to automate the running of this model because it needs to be updated every day, however I get an error that the model has no atribute. I have tried calling it as "arcpy.automate.Model_() and without the underscore as well ("_")  I am using spyder IDLE to run the code, it doesnt seem to work in the ArcPro python window either.

Heres the code:

import arcpy

arcpy.env.workspace=("C://Users/Planner1/Documents/ArcGIS/Projects/Automate_links_round2/Automate_links_round2.gdb")
arcpy.env.overwriteOutput = False

print ('Script started')
# import the toolbox
arcpy.ImportToolbox(r"C:/Users/Planner1/Documents/ArcGIS/Projects/Automate_links_round2/Automate.tbx")
print ('Toolbox imported')

#import the model
arcpy.automate.Model()
print ('Model imported')
print ('Script finished')

And here is the metadata for the tool:

Error:

runfile('C:/Users/Planner1/Documents/KML_Codes/Schedule Model builder.py', wdir='C:/Users/Planner1/Documents/KML_Codes')
Script started
Toolbox imported
Traceback (most recent call last):

  File "<ipython-input-6-a3a2d3d140f5>", line 1, in <module>
    runfile('C:/Users/Planner1/Documents/KML_Codes/Schedule Model builder.py', wdir='C:/Users/Planner1/Documents/KML_Codes')

  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/Planner1/Documents/KML_Codes/Schedule Model builder.py", line 19, in <module>
    arcpy.Model()

AttributeError: module 'arcpy' has no attribute 'Model'

Please let me know if I need to add any more info to help answer this question.

Thanks for the help,

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

Ok.. makes more sense now.  You might want to provide the 'alias' for the toolbox. 

If your model is named "Model" and your toolbox is named "Automate"

you should be able to... 

arcpy.ImportToolbox(r"C:/Users/Planner1/Documents/ArcGIS/Projects/Automate_links_round2/Automate.tbx, 'autostuff'"

then

arcpy.Model_autostuff or arcpy.autostuff.Model

View solution in original post

5 Replies
DanPatterson_Retired
MVP Emeritus

link to the documentation you are using since it doesn't even register in arcpy for Pro 2.4? 

 dir(arcpy.automate)
Traceback (most recent call last):

  File "<ipython-input-3-3922f2da4268>", line 1, in <module>
    dir(arcpy.automate)

AttributeError: module 'arcpy' has no attribute 'automate'




dir(arcpy.Model)
Traceback (most recent call last):

  File "<ipython-input-4-79fd79a0764b>", line 1, in <module>
    dir(arcpy.Model)

AttributeError: module 'arcpy' has no attribute 'Model'
0 Kudos
DavidMaack
New Contributor

Thanks for the response Dan, where do I find the documentation? Sorry I'm kind of a newbie. 

0 Kudos
DanPatterson_Retired
MVP Emeritus

David … it is this line …. arcpy.automate.Model() .  When I import arcpy and do a dir(arcpy.automate) it produces an error, so where does this line come from?

0 Kudos
DavidMaack
New Contributor

Ohh, sorry Dan. automate is the toolbox and Model() is the model name. I am going off of what ESRI has on their site. 

Schedule a model—ArcGIS Pro | ArcGIS Desktop 

import arcpy
arcpy.ImportToolbox(r"C:\path\myToolbox.tbx", "tbxAlias")
arcpy.myModel_tbxAlias(r"c:\pathToInput\inputFolder", r"C:\pathToGdb\output.gdb")
0 Kudos
DanPatterson_Retired
MVP Emeritus

Ok.. makes more sense now.  You might want to provide the 'alias' for the toolbox. 

If your model is named "Model" and your toolbox is named "Automate"

you should be able to... 

arcpy.ImportToolbox(r"C:/Users/Planner1/Documents/ArcGIS/Projects/Automate_links_round2/Automate.tbx, 'autostuff'"

then

arcpy.Model_autostuff or arcpy.autostuff.Model