1

I have a ArcGIS Pro model which takes a polygon shapefile (Site_boundary_master) and spatially joins various layers to it, finally exporting the final output to an Excel spreadsheet:

my working model

All the joining layers are kept in various File Geodatabases.

I saved the model as 'AutomationModel' (but in the properties dialogue for it, it's called 'Model222') in a toolbox called 'Automation.tbx'.

Running the model from ModelBuilder works fine.

I then created a .py python file (from a blank .txt file) and wrote a script to run this model this way:

import arcpy
print ('Script started')
# import the toolbox
arcpy.ImportToolbox(r"C:\Automation\Automation.tbx")
print ('Toolbox imported')

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

Pasting this code into the ArcGIS Pro python console, it work fine. Again.

Script to run model works in python console

However, when I edit the .py file in IDLE (ArcGIS Pro) and then run the script, it doesn't work at all:

errors in IDLE

Is it because I need to tell the script where all the input layers are stored?

I'm still a novice with Python.

1
  • Please present errors as text rather than pictures so that they are available to future searches. As per the Tour there should be only one question per question.
    – PolyGeo
    Commented Feb 8, 2018 at 22:41

2 Answers 2

5

Your model has a lot of what looks to be LAYER input parameters. Meaning the input to the tools have come from the ToC inside Pro. When you run the model outside of Pro (ie. using python at command line), those layers don't exist. Thats what your error screen shot is saying. I cant find the input data

While you aren't really exporting your model to a script, you sort of are. In this help topic on exporting models it states:

If your model used layers or table views that weren't created within the original model, those layers or table views will have to be created in the script using tools such as Make Feature Layer and Make Table View.

Meaning you'll need to run tools to "make layers" PRIOR to running your model through your script. (Here's a link to the ArcGIS Pro syntax for making a feature layer.)

Alternatively, you can go back and edit your model and drag the featureclass into the tool inputs (ie a full path like c:\mydata.gdb\fc)

1

The error you are getting for the most part look like "parameters are not valid" and "value does not exist" in the model. This makes me think that when you are accessing the file remotely in python it is not recognizing the correct environment. In short it does not know the proper full paths of the input parameters. Thus it is giving this error.

There are two things I would try right away

  1. Add a arcpy.env.workspace = "path/to/your.gdb" to the beginning of your script, this is essentially the same as setting the environment variables inside of arcpro (look here)

  2. You can export your model as a python script and debug it that way. Unfortunately this functionality was removed from Pro by ESRI (why, I do not know). So to do that you would have to open your model in ArcGIS Desktop. If you have access to Desktop there are instructions here.

    If you are at all python savvy this is a good way to do this. That being said executing spatial joins in python can sometimes be tricky for a beginner and may require you to create "field mappings".

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.