# Loop with Python

**URL:** <https://forum.dynamobim.com/t/loop-with-python/11195>\
**Category:** Uncategorized\
**Tags:** revit, loop, python, geometry\
**Created:** [April 21, 2017, 11:08am UTC](https://forum.dynamobim.com/t/loop-with-python/11195 "2017-04-21T11:08:43Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mvanleeuwen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mvanleeuwen/32/19994_2.png) [@mvanleeuwen](https://forum.dynamobim.com/u/mvanleeuwen)\
**Post date:** [April 21, 2017, 11:08am UTC](https://forum.dynamobim.com/t/loop-with-python/11195/1 "2017-04-21T11:08:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dimitar\_Venkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dimitar_venkov/32/2068_2.png) [@Dimitar\_Venkov](https://forum.dynamobim.com/u/Dimitar_Venkov)\
**Post date:** [April 21, 2017, 1:17pm UTC](https://forum.dynamobim.com/t/loop-with-python/11195/2 "2017-04-21T13:17:50Z")

</div>

You should give the LoopWhile node a try:

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/3/23960c3038432614d6e3ab02dea6f0f95f4e38a0.png)

[loop1.dyn](https://forum.dynamobim.com/uploads/short-url/vv5anDrzaa5r2w1yVHTTR3O8iDp.dyn) (9.6 KB)

[\_loop1.dyf](https://forum.dynamobim.com/uploads/short-url/n4Pg0ObfroudDFPwOy9b3KWSkxc.dyf) (11.5 KB)

---

<div class="post-metadata">

**Author:** ![mvanleeuwen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mvanleeuwen/32/19994_2.png) [@mvanleeuwen](https://forum.dynamobim.com/u/mvanleeuwen)\
**Post date:** [April 24, 2017, 7:37am UTC](https://forum.dynamobim.com/t/loop-with-python/11195/3 "2017-04-24T07:37:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mvanleeuwen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mvanleeuwen/32/19994_2.png) [@mvanleeuwen](https://forum.dynamobim.com/u/mvanleeuwen)\
**Post date:** [April 25, 2017, 8:34am UTC](https://forum.dynamobim.com/t/loop-with-python/11195/4 "2017-04-25T08:34:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dimitar\_Venkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dimitar_venkov/32/2068_2.png) [@Dimitar\_Venkov](https://forum.dynamobim.com/u/Dimitar_Venkov)\
**Post date:** [April 25, 2017, 10:02am UTC](https://forum.dynamobim.com/t/loop-with-python/11195/5 "2017-04-25T10:02:32Z")

</div>

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:

![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/d/bd65e08388d4ba70b362c3a818be8223195ca8d1.jpg)

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:

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/2/5280f346f675e450ea0d354b5c67fc6414ae001d.gif)

---

<div class="post-metadata">

**Author:** ![mvanleeuwen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mvanleeuwen/32/19994_2.png) [@mvanleeuwen](https://forum.dynamobim.com/u/mvanleeuwen)\
**Post date:** [April 25, 2017, 10:49am UTC](https://forum.dynamobim.com/t/loop-with-python/11195/6 "2017-04-25T10:49:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mvanleeuwen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mvanleeuwen/32/19994_2.png) [@mvanleeuwen](https://forum.dynamobim.com/u/mvanleeuwen)\
**Post date:** [April 25, 2017, 2:55pm UTC](https://forum.dynamobim.com/t/loop-with-python/11195/7 "2017-04-25T14:55:32Z")

</div>

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.

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/e/ee4d5b577ea63f298a803a7cda7dac560efa05a3.png)  
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…

---

<div class="post-metadata">

**Author:** ![mvanleeuwen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mvanleeuwen/32/19994_2.png) [@mvanleeuwen](https://forum.dynamobim.com/u/mvanleeuwen)\
**Post date:** [April 25, 2017, 9:57pm UTC](https://forum.dynamobim.com/t/loop-with-python/11195/8 "2017-04-25T21:57:48Z")

</div>

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.  
 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/5/056497eeb76c189909b94b24ba52a514004d43f2.png)

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/d/8d1ad2cf0278c1b3d0e46bb0788eb2678356248c.png)

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.

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/4/044c0a7814f66be0b51c0d4e634d83f3586a081c.png)

I am almost there (I think so 🙂) 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 😀

---

<div class="post-metadata">

**Author:** ![Dimitar\_Venkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dimitar_venkov/32/2068_2.png) [@Dimitar\_Venkov](https://forum.dynamobim.com/u/Dimitar_Venkov)\
**Post date:** [April 26, 2017, 1:37pm UTC](https://forum.dynamobim.com/t/loop-with-python/11195/9 "2017-04-26T13:37:01Z")

</div>

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](https://forum.dynamobim.com/uploads/short-url/vzlIihK0eFSgucbXLQNNyDtxfSb.dyn) (21.3 KB)  
[\_loop1.dyf](https://forum.dynamobim.com/uploads/short-url/jaRvUCqNua5RgmskKRv5aFO6wQL.dyf) (15.0 KB)

---

<div class="post-metadata">

**Author:** ![mvanleeuwen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mvanleeuwen/32/19994_2.png) [@mvanleeuwen](https://forum.dynamobim.com/u/mvanleeuwen)\
**Post date:** [April 26, 2017, 5:04pm UTC](https://forum.dynamobim.com/t/loop-with-python/11195/10 "2017-04-26T17:04:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ryujinn](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@ryujinn](https://forum.dynamobim.com/u/ryujinn)\
**Post date:** [June 12, 2018, 10:44am UTC](https://forum.dynamobim.com/t/loop-with-python/11195/11 "2018-06-12T10:44:00Z")

</div>

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?

 ![Loop%20Coordinates](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/a/3aaa382e44fc4184f4a4d6756e06f80c21bb5ef5.png)

Thanks!  
Francis

---

<div class="post-metadata">

**Author:** ![salvatoredragotta](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/salvatoredragotta/32/10078_2.png) [@salvatoredragotta](https://forum.dynamobim.com/u/salvatoredragotta)\
**Post date:** [June 12, 2018, 1:24pm UTC](https://forum.dynamobim.com/t/loop-with-python/11195/12 "2018-06-12T13:24:11Z")

</div>

@ryujinn please start a new topic an post your dyn
