Loop with Python

Hello All,

Who can help me with a python script? I’ve a curve at the start point of that curve I’ve a circel. The intersection with the circel and curve needs to be centerpoint of a new circel, and so on. But with the second and third circel there are always 2 intersections, so i need a script with a loop and filter out 1 of the instersections as input for the circel.

You should give the LoopWhile node a try:

loop1.dyn (9.6 KB)

_loop1.dyf (11.5 KB)

6 Likes

thanks for your reply, but i can’t manage it to do it with another curve as input and a radius that is variable, for example 1540 as input value. Any idea why? Dynamo will crash every time i run it.

Hi Dimitar,

i tried everything, but i can’t make the radius bigger that 2, dynamo will stop running. I also would like to give an arc as curve input, but that is also not possible. Could you explain a bit more what you are doing with your script? This LoopWhile is new for me and i can’t really find a good example similar to this one.

That’s most likely happening because your curve was not evenly divisible by the circles with that radius. Whenever you’re creating while loops, you have to always make sure that the end condition will be met, otherwise you’ll get stuck in an endless loop.

However, this is not easily done in Dynamo’s context, so it’s usually a good idea to test a chain of your custom node and see if it behaves as expected:

You can definitely build such a robust solution with just nodes, tho. Here’s a slightly more advanced example, that compares each new value to the last used value and passes a “false” bool if the new value stops increasing. That will make sure that even if the last circle does not intersect the curve, the iteration will stop and we won’t enter an infinite loop. I’m not gonna share it this time, because I want you to discover this on your own:

6 Likes

wow, great! thanks for the comment and i get to work myself :slight_smile:

wow dude, this is pretty genius… thanks! I understand how the loop works now. I tried to stop the iteration by looking at the intersection of circle and curve and the second last circle of the list, when they are the same, the iteration should stop.


But i can’t get it right this way…

The suggestion you made, look for increasing number is a bit complicated, because outcome (data) will increase at the bottom and at the top. So for example the radius is at index 2. When i let the ‘parameter.atpoint’ increase at the list, the radius won’t be at the same index. So do you make 2 separate lists here? 1 for the parameter at point and one for the rest?

It’s really a struggle for me… could you please share your script again? I would really like to know how you did this one…

I’ve created two separate lists, and it works when i link the custom nodes in a loop by hand, step by step. So the last one give a false value as input for the continue while parameter.

So when i try this in a loop, it will end running. So probably I am doing something wrong with the index… But it seems that you didnt need to create separate lists.

I am almost there (I think so :slight_smile:) But still, I am very curious how you did it. You don’t seems to need separate lists… And why did you created an empty lists? I don’t understand that one…

Anyway thanks for so far, learnt a lot of this :grinning:

Looks like you’re almost there. I use the empty list as a container for the circles. Also you really only need the last parameter value, not a list of every single parameter. Here’s my version of the flow:

loop1.dyn (21.3 KB)
_loop1.dyf (15.0 KB)

Great thanks a lot!! I am on vacation right now but when I am back I will get to it!

Hi Guys!

I am currently working on something similar. To be more precise, I am trying to create a list of coodinates(x and y) with a given list count(say 10). and every item will have “x” increase +450.

Any Ideas on how to do this?

Thanks!
Francis

@ryujinn please start a new topic an post your dyn