For Loop in DS - Distances between multiple Points

I want to get a list with all the distances between a set of intersection points.
Don’t know how to create an adequate “For Loop” in DS, so in the end there would be one large list containing all the distances. The distance lists for two points have been created to get an idea about what the result should look like.

Thought about creating an empty list “distances” and then adding the contents of the “dist_rest_p” lists to it. But I can’t find a “List.Append” command like in Python? Is there anything comparable in DS?

Intersection DS 05.dyn (15.6 KB)Intersection DS 04.dyn (19.7 KB)

Search your library for List.AddItem.

Also I think you should consider trying some of this stuff with nodes before you jump straight to scripting. The ‘node to code’ function will help transition over.

Here is a sample code that iterates through a lists and returns another one.

In your sample you are creating a list (distances) but you are never modifying or adding anything to that list. This is the reason your output is empty.

1 Like

Had a look at the ‘List.AddItem’ nodes and their ‘node to code’ translation and saw that lists modified but adding items are recursive if used inside an imperative block.

I updated the code in “Intersection DS 04.dyn” and also introduced the ‘List.AddItemToEnd’ command, but the “distances” list still remains empty?

Also tried something similar with a simple line pattern where ‘for p in points’ and ‘List.AddItemToEnd’ did both work.

Intersection DS 04.dyn (21.9 KB)

The problem seems to be the distance calculation inside the loop.
By adding a list of fantasy numbers, one can see that ‘For Loop’ and ‘List.AddItemToEnd’ are working.
But that is still no solution…

Thank you for the list item replacement sample.

Found a completely different solution to the problem.
Drew new lines between all intersection points, then extracted ‘Curve.length’ from those new lines.

1 Like