How do I make the While Iterator work in Model Builder

1126
5
Jump to solution
10-14-2022 12:42 AM
LindsayRaabe_FPCWA
Honored Contributor

So seeming as how I've had no breakthroughs with my other question (Why isn't my model iterating for all features (2 iterators using sub models)) I thought I'd try another approach. 

Now I'm using the While Iterator to try and stop an iteration when a feature class contains X number of rows. 

It seems like there aren't many options. Just Inputs and Continue if True/False. I was hoping that if I put both inputs in, then when they matched, it would recognise it as True and stop. Apparently not the case. 

LindsayRaabe_FPCWA_0-1665733234198.png

LindsayRaabe_FPCWA_1-1665733239693.png

LindsayRaabe_FPCWA_2-1665733273407.png

I'm guessing I need to include some sort of expression step that passes True/False to the iterator? How would this look?

 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
1 Solution

Accepted Solutions
LindsayRaabe_FPCWA
Honored Contributor

Never mind. Figured it out myself. Needed to use a "Logical - If Value Is" tool to generate the True/False value which in turn fed into the While Iterator. 

LindsayRaabe_FPCWA_0-1665734033867.png

 

Lindsay Raabe
GIS Officer
Forest Products Commission WA

View solution in original post

0 Kudos
5 Replies
LindsayRaabe_FPCWA
Honored Contributor

Never mind. Figured it out myself. Needed to use a "Logical - If Value Is" tool to generate the True/False value which in turn fed into the While Iterator. 

LindsayRaabe_FPCWA_0-1665734033867.png

 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
JohannesLindner
MVP Frequent Contributor

Try using Calculate Value in front of the While.

Make Destination Count and Updated Origin Count into variables and use this expression in Calculate Value:

 

%Updated Origin Count% == %Destination Count%

 

 

This will return True if the counts are equal. So choose that in the While block.

Nevermind, your approach is better.

 

 

 

Honestly, if you get to the point where you need iterations, wouldn't it be easier to just write a little Python script and package that in a script tool?


Have a great day!
Johannes
LindsayRaabe_FPCWA
Honored Contributor

Thanks for the tip - I'll look at implementing that on Monday. It makes sense to cut down as many steps as possible.

As for python in place of iterators, I could do, but I'm far too novice to be efficient at it, and nobody else here has much python understanding so model builder is an easier solution to troubleshoot/fix should I not be around (in theory). 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
LindsayRaabe_FPCWA
Honored Contributor

Actually - just realised that this tip won't quite work in my case. The replication effect I'm going for isn't to match the total number of features already existing in Destinations, but what the total will be once Destinations are Replicated for each unique Origin location too (so a multiplying effect) which is why the Calculate Value is there at all (AxB = C) then test if B=C: false - add another lot on | true - stop iterating. 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
JohannesLindner
MVP Frequent Contributor

Yeah, I used the wrong value, sorry. Should have been Target Value instead of Destination Count

And fair point about using Python. When I leave my current job and my scripts and tools stop working for some reason, nobody will be able to fix them. But then again, nobody would be able to fix ModelBuilder either. I'll just have to hope that they keep working...


Have a great day!
Johannes