The misterious "LoopWhile" node


#1

Hello,

I’ve been trying to wrap my head around the looping syntax in Dynamo. For the last few releases there has been a new node called “LoopWhile”.

Would anyone be kind enough to show me some basic looping examples that utilize that node?

2014-12-09_170222


#2

you are almost there, your continue while function is not a function!

you need to use the function compose node to compose curve length and less than into one function.


#3

Thanks for the hint, Michael! I had another go at the problem but it seems I’m still not getting it. What am I doing wrong this time?

2014-12-10_100833


#4

yes, very close now, if you look at the code again you’ll see that you’re applying the loop body on the init value in each iteration of the while loop. What this does is let you continually modify the init value each time you go through the loop.

Your function there expects a number, but you’re init variable type is a line.


#5

Thanks, Michael - that made things much more clear.

Looping an integer:

Capture

 

Point loop:
Capture1

Line loop:

Capture2

I think my confusion came from the fact that I wanted to modify the output of the initial function by modifying its arguments - exactly like in the design script example . However it seems that this is not possible with OOTB nodes.(unless you don’t nest custom nodes) It really shows the benefits of design script.

Capture3

There is no way to add to the integer feeding into the point, or add a vector to the point because of the way the node is set up. It applies the “loopbody” function directly to the output of the initial function and not to its arguments.


#6

Thanks to both Dimitar and Michael for helping me to sort out the LoopWhile node. I cannot say I understand exactly what the Function.Compose node is doing, but it works. I was able to use a LoopWhile node to generate the necessary string of zeros for zero padding, given the length of the string to be zero-padded and the length of the final string.

ZeroPaddingStringCustomNode

 

 


#7

Is it possible to use the LoopWhile to run a custom node? Not sure if I asked the question correctly, so here’s my explanation. I have created a list of wall types. I would like to run the LunchBox Wall Element Collector on each wall type. Since the list is generated from the Revit model, the number of wall types may vary, thus I would like to run it for a loop determined by the wall type count.


#8

I believe you’re making your life unnecessarily difficult. It might be possible to run custom nodes through the “Loop while” node but so far I haven’t been successful.

You already know that your list has a fixed width because there are only so many walls in the project. LoopWhile is more often used for when your input is as unknown variable. I suggest you try the “List.Map” node instead. It iterates through each item of a list:

2015-01-09_105058

 

Query all wall types and map those through the wall collector node. If there are none that match that wall type, you’ll get an empty list.


#9

I don’t think I explained what I am trying to do very well. I am collecting all the walls from the Revit model, selecting the exterior walls(ignoring interior walls) and then offsetting a line. If all the walls are the same type, it works pretty well. I was hoping to have it loop through the all exterior wall types and offset for each…which prompted my question. As you will see in the image, I have two instances of Lunchbox Wall Element Collector where I run into the issue. Should I still use the List Map as suggested above?

2015-01-09_0900


#10

Dynamo gives us a lot of options. There are multiple ways to solve a problem. It might be possible to run a Loop while for your workflow but I think that “List.Map” will be an easier solution:

Capture1

 


#11

Thank you Dimitar, i really do appreciate your willingness to help! That works great.


Loop While to execute a task in chunks
#12

@ david function compose takes the nodes in order from top to bottom and orders their execution like this bottom(top(x)) - where x is some input parameter (a number, a line, etc) that the new composed function is applied to.

So whatever the return value of top(x) is will be passed to bottom()


#13

Thanks. That helps me understand what Function.Compose is doing. I am still not certain why my < [less than] node output could not be plugged directly into the continueWhile input of the LoopWhile node (with the String.Length node output going into the x input of the < node), but I will accept that it is necessary.