How to create a for loop

Hello,

I’m looking for a way to create a for loop on Dynamo.

Right now, I have a quite simple program. An element is linked to a group of nodes that calculate a value.
I would like to apply the group of nodes to a list of elements and get each value stored in a new list. The schema here below might explain it better :

Sadly, I can’t just link the list to the group of nodes, because pieces of information from each element get mixed.

Therefore, a For loop that applies the group of nodes to each element would be handy.

However, I can’t figure out how to make it and the While loop goes over my head :sweat_smile:

Some help would be greatly appreciated
Thanks in advance :smile:

Hi @elsa.guiton,
Welcome to the Dynamo community.
Can you share a screenshot of your graph which shows what you are trying to do?
I think you can use Python or create a custom node and get the job done.

1 Like

I’m trying to return the length of a pipe that goes through a bounding box.

1/On one hand, I collect in a list all the surface of the bounding box. On another hand, I sort the pipes collect by the bounding box into two lists. The first list regroups all the pipes that are in the bounding box. The second one has the pipes passing through. Then I get the geometry of the pipes of that list.

2/ I’m preparing the variables needed for my study. Those are :

  • the maximum and the minimum corner of the surface (those are points)
  • the end-point and the start-point of the pipe’s line.

3/ That’s the Liang-Barsky algorithm that will give me the intersection point between the surface and the line. I need two surfaces to have the 3D coordinates of the intersection points. For example : (X,Y) and (X,Z).

4/ I create the points.

Here’s the Liang-Barsky algorithm.

I found a solution by reorganizing my lists and sublists.

I had to make sure that the data of each point are always into two distinct sublists.

Hi Elsa,
I saw that you found a solution to your problem.
However, I got intrigued in this workflow. Can’t you just intersect the location lines of the pipes with the solid (cuboid) of the bounding box to get the portions that are inside?

Hi Viktor,
No, I can’t. The bounding box that I use works like an all or nothing. Either I get the whole element, or I get nothing. I tried :

  • turning the bounding box to a cuboid and using the Geometry.IntersectAll node but it returned me the entire pipe’s line.
  • using the Element/IntersectsSolid node but it returned me the pipe.
  • using the Curve.IntersectAll node but nothing showed up.

So, the Liang-Barsky algorithm is the only way out that I found :tired_face: . It’s quite long to implement because there are a lot of “what if” to answer but it’s efficient when it works.

However, if someone has a better and lighter solution, I’m all ears for it! :smile: