How to loop over a group of nodes N times

I have a group of nodes above. My goal would be to find a way to run this script N number of times based off of a variable? The technical term is a for loop. But there doesn’t seem to be a for loop in dynamo.

Can someone please help me find a way to loop over all of the nodes in the image?

The code above does the following:

  1. Grabs all schedules
  2. Gets schedule by searching for a string
  3. Duplicates the schedule with a new name (adds a 2 at the end)

Thanks.

1 Like

@NateWalchenbach ,

i followed your steps… more or less look…


KR
Andreas

Try to avoid thinking about ‘loops’ in Dynamo.

Instead, create lists of inputs to feed into the nodes you’re trying to loop, and if required change the input @ levels and the lacing.

From what you describe, you’ll want to input into the duplicate node a list of the schedules to duplicate. You can use this same input list, get the elements names, then add “2” to the end and send that into the name input.

If you wanted multiple duplicates of one schedule, instead of trying to loop, you just input in that schedule into the node, then for names you create a list of 1 to 5 or whatever you require.

If you wanted to loop over multiple string searches, you might create a Data Shapes UI to allow you to input in a list of search terms, or provide a list of all schedules with checkboxes you can tick to select the schedules to duplicate.

3 Likes

The way that Dynamo works, each node is executed once, not for each value in its inputs. If a node has a list of input values then it will still only run once but will return a list of output values to match the inputs. This means that you can’t have a “loop” where multiple nodes run for one value and then again for another value (unless you try with functions, but that’s really not necessary most of the time). Instead, you need to setup your nodes and your graph to handle multiple inputs where necessary. Essentially, it’s just list management. Or you can transition to python and use loops there.

2 Likes