Model runs in ModelBuilder but gives error when run from Python Script

1415
4
04-15-2019 03:17 PM
NealBanerjee
Occasional Contributor

Hello,

I have created a toolbox and developed a series of about 20 tools in ModelBuilder that represent different components of an analysis.  Each model runs fine without error when run in model building or executed in the Python command line within ArcMap.  Some of the models are fairly complex and involve iterators, in-line variables, etc.

I created a script tool with an associated Python script that basically runs all the component models in sequence.  Most of the models run fine, but a few that have iterators keep giving error when run through the Python Script tool.  The first model that the script chokes on involves an iterator with the 'Get Field Value' tool that then writes a value to a variable field name based on the get value value.  The values that  should be produced start at 2 and go to 500.  However, when I run Python script it for some reason returns a value of 1 and then bombs.  Again model run fine in model builder.   Below is an annotated screenshot of model.

Im stumped where/why it is return a value of 1.  Any ideas on why something in ModelBuilder works but not the identical process run from python script?  The input parameters and model reference work fine - so it is definitely something occurring within the model.  I cant imagine it is something in the script itself because it is just calling the model and the other models run fine.

Any help would be greatly appreciated

Thanks!

Neal

0 Kudos
4 Replies
PaulHuffman
Occasional Contributor III

How do the python script lines run in a python window in ArcDesktop or Pro? I wonder if you might need to implicitly call the python library with import arcpy to run in python outside of an ESRI environment.  Did your python IDE throw any error messages?

0 Kudos
NealBanerjee
Occasional Contributor

Hi Paul - The python script (as script tool) is intended to run in the ArcMap session since it references some standard feature layers (rather than explicit feature classes) and uses in-memory layers.  Attached is the actual error Im getting.  Oddly enough, is I have an earlier version that I backed up that works with the older data.  Maybe something got corrupt in my toolbox, but just very odd and seemingly random

0 Kudos
curtvprice
MVP Esteemed Contributor

Did you validate the model before running it from Python?

0 Kudos
PaulHuffman
Occasional Contributor III

I thought I recently had a problem like this. I found it.  I found out that outside ArcDesktop I had to also explicitly check out extensions. https://community.esri.com/thread/219120-why-doesnt-sa-slope-get-called-as-expected-in-python-script 

0 Kudos