Select to view content in your preferred language

ModelBuilder iterator with variable outputs for second Model

2880
3
Jump to solution
10-26-2015 09:17 AM
DavidTreering
New Contributor II

I have a model and a sub-model within it and the output of my sub-model uses a local variable name to create and save new Feature Classes in a GDB Feature Dataset. 

Variable name= Crime_Type (eg. Assault, Battery, Homicide, etc.)

Output = %Crime_Type% (this is a model parameter)

The main model should take this new FC in iteration 1 and run to completion before the first model iterates a second time.

I have two problems:

First, the %Crime_Type% input for the main model is not found because it is being treated literally (Failed...cannot find ...Crimes/%Crime_Type%) instead of looking for the file that was created in the sub-model (.../Crimes/Assault).

Second, when running the main model, the sub-model runs to completion, iterating as it should, before the main model starts.  I need the sub-model to run one iteration and give that to the main model before the sub-model iterates again.

I may be missing something simple with Preconditions, but I am stumped.  Any advice is appreciated.

0 Kudos
1 Solution

Accepted Solutions
FreddieGibson
Regular Contributor II

In regards to your first question, which tool is giving you the error about the data not existing? Could you show a screenshot of the GPDialog for that tool?

In regards to your second question, ModelBuilder will not allow you to run the submodel in that manner. The SubModel is designed to run to completion prior to returning control back to the parent model. I would think that you'd need to switch your Main and Sub models. The Sub-Model should be used as the Main-Model to select the crime type. For each crime type you would need to run your Main-Model to completion as a Sub-Model to process the parks against the crime type.

View solution in original post

3 Replies
FreddieGibson
Regular Contributor II

In regards to your first question, which tool is giving you the error about the data not existing? Could you show a screenshot of the GPDialog for that tool?

In regards to your second question, ModelBuilder will not allow you to run the submodel in that manner. The SubModel is designed to run to completion prior to returning control back to the parent model. I would think that you'd need to switch your Main and Sub models. The Sub-Model should be used as the Main-Model to select the crime type. For each crime type you would need to run your Main-Model to completion as a Sub-Model to process the parks against the crime type.

DavidTreering
New Contributor II

Forget the first part of my question then.  If the sub model runs to completion, then there would not be an iterated variable passed on to the main model.

So for the second question, this is actually two levels of a 4 level nested iteration, so i need the order to be this way.  I'm thinking I should remove the iterators from all my models and export them as python scripts.  Then I can write easy nested for loops to do the job.  Does that sound reasonable, or possible?

0 Kudos
FreddieGibson
Regular Contributor II

Yea...this workflow could work either way. The choice is just dependent on the environment you're most familiar with. Python would be a lot more flexible, but will require both knowledge of python syntax and programming logic. ModelBuilder won't require any knowledge of programming, but it will require that you understand its limitation when attempting to accomplish workflows that involve tasks that aren't run in a strictly linear manner.

My only tip in exporting the models to scripts is to treat the scripts as skeletons that you need to clean up and not as ready-to-run scripts. If needed you can just make separate the models into their individual tasks and call the models directly from python to implement your logic.