Select to view content in your preferred language

How to stop a model builder feature iteration after the condition is fulfilled

5440
7
Jump to solution
06-08-2018 10:44 AM
BartekBlatkiewicz
New Contributor II

Hello, im trying to build a model that iterates feature classes until one of the feature fulfill a condition. The problem is i dont know how to stop the model from further iterations. I tried while but i couldnt figure it out.

0 Kudos
1 Solution

Accepted Solutions
ChrisDonohue__GISP
MVP Alum

A general observation - when folks find they need to use iterators with conditions, that often is the point they end up going to Python scripting instead of Modelbuilder.

That said, there are some options in Modelbuilder to do what you are looking for.   But Modelbuilder is limited in this regard.  It will depend in part on how complex a condition is that you want to trigger the end of the run and whether the data is structured to support this.

Some possibilities:

  • Use a While Iterator (likely part of a "model within a model strategy" as mentioned by Joe Borgione )  While—Help | ArcGIS for Desktop 
  • Use a Stop "Model-only tool".  This can be useful  if one does not want to do the "model within a model strategy"  Stop—Help | ArcGIS for Desktop 
  • It may be possible to write a short bit of Python code to do the check for when to stop, then import that into Modelbuilder as a script tool and then add it to the Model.  A quick tour of creating tools with Python—Help | ArcGIS for Desktop 
  • There are Iterator properties that can be set at the Model-level that may do what you want.  In the Model itself, click on "Model" in the top menu, then  "Model properties...", then in the window that pops up the "Iteration" tab.  There are several possibilities here.  This may also be useful in conjunction with a script tool that checks for the condition, then sets a variable false when that happens.                                                                                                                                                                                     

Chris Donohue, GISP

View solution in original post

7 Replies
JoeBorgione
MVP Emeritus

These two articles suggest the same thing: nest a model within a model....

https://community.esri.com/thread/163666 

arcgis desktop - How to Exclude Processes from Iteration in ModelBuilder? - Geographic Information S... 

That should just about do it....
BartekBlatkiewicz
New Contributor II

I saw this but it doesnt solve my problem. There could be many features that fulfill the conditon but i want it to stop after first one. That the model output is only that one first feature.

0 Kudos
JoeBorgione
MVP Emeritus

It can be done in python, but that's probably not going to help you either...

That should just about do it....
0 Kudos
ChrisDonohue__GISP
MVP Alum

A general observation - when folks find they need to use iterators with conditions, that often is the point they end up going to Python scripting instead of Modelbuilder.

That said, there are some options in Modelbuilder to do what you are looking for.   But Modelbuilder is limited in this regard.  It will depend in part on how complex a condition is that you want to trigger the end of the run and whether the data is structured to support this.

Some possibilities:

  • Use a While Iterator (likely part of a "model within a model strategy" as mentioned by Joe Borgione )  While—Help | ArcGIS for Desktop 
  • Use a Stop "Model-only tool".  This can be useful  if one does not want to do the "model within a model strategy"  Stop—Help | ArcGIS for Desktop 
  • It may be possible to write a short bit of Python code to do the check for when to stop, then import that into Modelbuilder as a script tool and then add it to the Model.  A quick tour of creating tools with Python—Help | ArcGIS for Desktop 
  • There are Iterator properties that can be set at the Model-level that may do what you want.  In the Model itself, click on "Model" in the top menu, then  "Model properties...", then in the window that pops up the "Iteration" tab.  There are several possibilities here.  This may also be useful in conjunction with a script tool that checks for the condition, then sets a variable false when that happens.                                                                                                                                                                                     

Chris Donohue, GISP

BartekBlatkiewicz
New Contributor II

Thanks everyone for help. I have mange to do this like that. I know it doesnt look pretty but it works. Is it possible to put select by location or attribute after iterate feture classes so i dont have to add every one layer to the model? Even if i tried to make via submodel i still cloudnt integrate select by location with submodel output.

0 Kudos
BartekBlatkiewicz
New Contributor II

I finally figured out how to do what i wanted from the begining.

curtvprice
MVP Esteemed Contributor

What a good solution. I was thinking you could use Calculate Value to test your condition (return true and false) and making that a precondition to the first tool in your processing chain (Make Feature Layer). This of course wouldn't stop the iterator but would keep anything from happening after the condition became true. Stop is a much better solution.