Need help with while loop in Dynamo

Hello everyone,

I am trying to use a while loop in Dynamo, but it doesn’t seem to be working as expected. Here’s the script I’m using:

Basically, I want to create a loop that gives me random variables n times to understan how loop node works but I even couldn’t achive it
If anyone has experience with using while loops in Dynamo, I would really appreciate your help in figuring out what’s going wrong here. Any insights or suggestions would be greatly appreciated!

Thank you in advance for your time and assistance.

Best regards,

There are a couple things:

  • Does your custom node currently return a function?
  • The expected output from your node is a list. I don’t think you can use a list as the iterative value in a LoopWhile node.
  • Math.RandomList returns random values in the range of 0-1. Which means that value will always be less than 2.

The loopBody function has to be able to run and return a value that then becomes the next value used in the loop. The node only returns the final value though, so you won’t really see how many times it ran.

This is not an answer, but I recommend you to use python script for looping.
It’s even more easy and fuctional.

2 Likes

Yeap, I’m with @Hyunu_Kim on that one :slight_smile: It’s basically 3 lines of python code. Doing this with nodes seems much more complicated

1 Like

Thanks for answer. I already think about it but the problem is I am gonna use a function inside that loop. I dont know how to use dynamo function inside python node. Do you have any idea about it ?


Here I have a custom node which gives me max stress of truss after FEM calculation on RSA. With function apply node I can make the calculations for different inputs in the loop. If I use python script I don’t think there is a way to do it same.

You can make a node to loop using python by breaking the node and analize it.

I don’t know that robot will let you loop like this, as the outcome would basically be appending N trusses atop each other… Would love to hear otherwise.

I am sorry,I didn’t understand what you mean.

Actually, it let me loop like that.


This script is what is happening inside that custom node. When I change the values for example height, sections, truss type etc… I get the results from robot. I don’t need to restart robot or dynamo.The structures are not overlapping But when I create custom node from this script, it does not work like that anymore.