How to create a loop

Hello All,

I am trying to create a randomisation of the height for 5 points so that I have n number of heights for each of the 5 points. From the image below you can see that the polycurve node is not working because of too much information going into it.

I think I need to create a loop so that only a single height for the 5 points are going in at once. Instead of n number of height x 5 points.

Can someone please advise if this is the correct procedure? is there a node for creating loops?

Thank you in advance.

It’s giving you two polycurves and the rest are nulls so I doubt it’s because you have too much information. More likely there’s something wrong with your point list. What does the error read?

There is a while loop in dynamo but you’re better off using the python node and writing your own loop.

Hi @Alien
Thanks for your reply. The error is as below:
Warning: PolyCurve.ByPoints operation failed.
Unable to create Line. Points are likely coincident

Also, what I have realised is that it plots all the points. but I only want it to plot one set at a time. So I think I need to make a loop. Can you send me any examples of a python code for a loop.

While you could, this is not required. Look into lists and lacing examples in the dynamo primer: What’s a List | The Dynamo Primer (dynamobim.org)

Hello
try to remove duplicate Points with PruneDuplicates node

Thank you both for replying.

The outcome of this script is to generate n umber of design options (different heights). At the moment it is plotting all the design options at once. but I want it to do it one by one. My work is based on an example from the Autodesk University but my structure is different and that example used a node called Truss Structure Analysis. but I couldn’t really find the node so I am trying to create my own script.

The PruneDuplicates node worked but I think I need to create a loop as the Truss Structure Analysis node from Autodesk University example used loops.

I will look into lists and lacing examples and see if that can resolve the issue.

Hello,

Now I have been able to input 1 design option at one time as shown in the image below. The “List.Map” output shows all the design options (each list is a design option) and the “List.GetItemAtIndex” shows a selected design option.

My question is how can I tell Dynamo to run all the design options and then I select which one to view.
Because at the moment it is vise versa, so each design option has to be calculated on its own.

I want to be able to send all results for each design option to excel and plot a graph to see which one is best.

Thanks for your help.

Remove the List.GetItemAtIndex node, and process the full set of data all the way downstream. When it’s done, use the List.GetItemAtIndex to pull the valid portions into a report type format.

Hi @jacob.small

Thanks for replying. I have tried to do that but it plots all the points. As seen from the image below the output of the “List.Map” goes into the Z input of “Victor.ByCoordinates” node. So it will plot all the coordinates.

That is what the loop would do… run them all and then select the one you want. Am I missing something?

yes exactly, you’re right. But I dont know How to create a loop. Some example would really help.

There isn’t a need for a loop - just let the built in lacing and list mechanism do the job. That is the case for any for loop in Dynamo.

You can learn about lacing and list levels on the Dynamo Primer (https://primer.dynamobim.org/), and on this YouTube series (Architecture Community Virtual Meetups - YouTube). For the YouTube series, the last three Dynamo sessions there - lists, lacing, and levels are what you are after. Educational stuff is about 15 minutes in and lasts for about 15 minutes. :slight_smile:

1 Like

Thank you very much @jacob.small for your help. I will have a look.

if you have a case where you need a loop - or if you just want to use one over lacing for some reason checkout:
the spec:
DesignScript/LanguageSpec.md at master · DynamoDS/DesignScript (github.com)

and the designscript guide:

look for while and for loops - you will need to use an imperative block which will disable replication in that context.

1 Like