Select to view content in your preferred language

ModelBuilder / scripting issue

4371
6
02-13-2015 10:42 AM
MarcoBoeringa
MVP Regular Contributor

Hi,

I have a problem that I can't figure out yet, and maybe someone else has dealt with a similar issue.

The issue I encounter is that I have one big main model build in ModelBuilder that contains a number of disjunct / unconnected process streams of submodels and tools. This is intentional, as the output of one process flow is not the input for another one.

In total, there are five of such "unconnected" process streams in this main model. The order in which they are run, is actually irrelevant, as long as everything is run.

Now I can run this model fine directly, and it does exactly what it needs to do, and all process flows are run and output data properly created. So no problem here.

However, since I wanted to implement some Python validation code for the model's inputs, I thought I could simply "wrap" the model in a Python script, duplicating all the input variables in the Python script settings, and add validation code there, as you can't define custom validation for a ModelBuilder model

Fine, that seemed easy enough... not so! After implementing this, I discovered that after just one of the five process flows is finished, somehow ModelBuilder returns back to the script... This means that four of the five unconnected process flows aren't being executed!

I have no idea why this is. I have made several attempts at fixing this, for example by using the ModelBuilder specific Collect Values tool to collect all outputs of the unconnected subprocesses, setting preconditions, and set the output of the Collect Values tool as the only output for the model, but all of these attempts, proved futile. In all cases, the model bails after the first process flow is executed, returning back to the script. The script then simply reports being "Completed" without any errors...

Anyone know of how to solve this, or is it really impossible to call such a type of ModelBuilder model with multiple unconnected process flows from within a Python scripts, and do I really need to split it all up, and call five separate models from within my script?

Tags (2)
0 Kudos
6 Replies
DanPatterson_Retired
MVP Emeritus

Just a quick question...have you exported the model that works out to a python script to see the order in which things are done?  And if so, does the resultant script work if you run it?

0 Kudos
MarcoBoeringa
MVP Regular Contributor

Dan Patterson schreef:

Just a quick question...have you exported the model that works out to a python script to see the order in which things are done?  And if so, does the resultant script work if you run it?

No, I hadn't tried. But now looking at the exported data, it can't be run, as I see a number of vital huge "list-of-value" type string variables, not properly incorporated. It seems a bit of a jumble.

Anyway, I do see the five different subflows reflected, in the order I restricted them by setting pre-conditions (not that the order actually matters in this case...).

By the way, this is ArcGIS 10.2.0

0 Kudos
DanPatterson_Retired
MVP Emeritus

The jumble reflects the way things were done within the model or sub model.  The only way to fix that, is to examine the sequence that each part of a model was defined, then reorder it within the model...there are limited tools for doing that in modelbuilder.  If anything was defined as a parameter ... P ... in the model, it is now a local variable and won't be changed.  In short, modelbuilder makes a nice visual, but prefer to breakdown complex workflows and do them manually, then copy the python code snippets out of the Results Window so that I am sure to get environment settings exact and the sequence correct.  I posted a blog post on using the Results window geared to students learning how to program, which is not your case, but a very useful logging tool in Arc* that few use to its full potential.

Good luck

0 Kudos
MarcoBoeringa
MVP Regular Contributor

I understand, but ModelBuilder's visual approach can have it's advantages as well. Actually, my model is a nice mixture of small Python scripts to do stuff that can't be easily done with ModelBuilder, and other processes setup within models that show the overall layout and process flow.

Since this is ultimately intended for a non-programmer's audience as well (I am working on an advanced ArcGIS Renderer for OpenStreetMap: see here for early results, I have since made significant changes: OSM Renderer for ArcGIS (Page 1) / Development / OpenStreetMap Forum ), this will need to be a bit more accessible than just "code"...

Thanks for the response anyway Dan.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Thanks for posting the link Marco, I will keep it bookmarked ... good luck

0 Kudos
MarcoBoeringa
MVP Regular Contributor

Dan Patterson schreef:

The jumble reflects the way things were done within the model or sub model.  The only way to fix that, is to examine the sequence that each part of a model was defined, then reorder it within the model...there are limited tools for doing that in modelbuilder.

Admittedly, the way to force process flow effectively within the graphical ModelBuilder environment takes a bit of time to understand fully, it is not the most clear part of ModelBuilder for someone learning ArcGIS.

But once you really understand how to use preconditions, and how to take advantage of Calculate Value and Merge Branch in this context, you can in fact control the exact flow and order of processes in ModelBuilder quite effectively in my experience.

The models of my Renderer are actually a nice example of small branched sections using preconditions, including boolean ones calculated by Calculate Value, to fully control the desired process flow. I have made extensive usage of these options.

Once it is out, it may give some nice examples for you to use in your teaching practice.