# Looping through a list

**URL:** <https://forum.dynamobim.com/t/looping-through-a-list/37389>\
**Category:** Uncategorized\
**Created:** [June 19, 2019, 7:33pm UTC](https://forum.dynamobim.com/t/looping-through-a-list/37389 "2019-06-19T19:33:34Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![hle](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hle](https://forum.dynamobim.com/u/hle)\
**Post date:** [June 19, 2019, 7:33pm UTC](https://forum.dynamobim.com/t/looping-through-a-list/37389/1 "2019-06-19T19:33:34Z")

</div>

The goal of this script is to draw a line from all items within one index to all the items in another index, I’ve manage to get it working properly but it requires me to manually create and input the index that is required, this is both clunky and inflexible, is there anyway for dynamo to loop through the 2 list and draw lines between the corresponding index’s, as long as there are still index’s? any insight into the subject would be greatly appreciated, Thanks!

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

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [June 19, 2019, 8:13pm UTC](https://forum.dynamobim.com/t/looping-through-a-list/37389/2 "2019-06-19T20:13:52Z")

</div>

Go through the Primer and look into List Levels. That will let you control how functions “loop” through lists and sublists.

---

<div class="post-metadata">

**Author:** ![SeanP](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/seanp/32/42560_2.png) [@SeanP](https://forum.dynamobim.com/u/SeanP)\
**Post date:** [June 19, 2019, 8:13pm UTC](https://forum.dynamobim.com/t/looping-through-a-list/37389/3 "2019-06-19T20:13:52Z")

</div>

You should be able to make that work with List Level and Lacing if you are trying to go from each point to all the others.

---

<div class="post-metadata">

**Author:** ![hle](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hle](https://forum.dynamobim.com/u/hle)\
**Post date:** [June 19, 2019, 10:22pm UTC](https://forum.dynamobim.com/t/looping-through-a-list/37389/4 "2019-06-19T22:22:51Z")

</div>

I have tried changing all the list levels and lacing, but none of them seems to return the correct results

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [June 19, 2019, 11:46pm UTC](https://forum.dynamobim.com/t/looping-through-a-list/37389/5 "2019-06-19T23:46:20Z")

</div>

Looks like you are drawing lines from A[0] to B[0], A[1] to B[1], A[2] to B[2], A[n] to B[n].

List.Join to get a new list of both A and B. Then List.Transpose to get the marching pits of indices. Then Line.ByBestFitThroughPoints to finish it off.

---

<div class="post-metadata">

**Author:** ![hle](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hle](https://forum.dynamobim.com/u/hle)\
**Post date:** [June 20, 2019, 2:43pm UTC](https://forum.dynamobim.com/t/looping-through-a-list/37389/6 "2019-06-20T14:43:27Z")

</div>

Thanks for the feed back, however when it passes through the Line.ByBestFitThroughPoints node I get the error “Warning: One or more of the input types are not matching. Couldn’t find a version of ByBestFitThroughPoints that takes arguments of type (\_\_array)”

do you know how to fix this? should I convert the list to something else?

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [June 20, 2019, 4:47pm UTC](https://forum.dynamobim.com/t/looping-through-a-list/37389/7 "2019-06-20T16:47:28Z")

</div>

List levels likely. Try @L2.

---

<div class="post-metadata">

**Author:** ![hle](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hle](https://forum.dynamobim.com/u/hle)\
**Post date:** [June 20, 2019, 6:59pm UTC](https://forum.dynamobim.com/t/looping-through-a-list/37389/8 "2019-06-20T18:59:30Z")

</div>

I tried changing List levels to @L2 but its still returning the same error, just to make sure this is what you meant right?

 ![recursion](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/7/f7570d4a4296ec75c6e03f66544f5e3eedcc43b2.png)

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [June 21, 2019, 12:12am UTC](https://forum.dynamobim.com/t/looping-through-a-list/37389/9 "2019-06-21T00:12:14Z")

</div>

You can’t draw lines from aardvark to cantaloupe any easier then you can from element to element. You want to go from point to point.

Add an Element.Location to get points (hopefully - it could return lines too depending on what you have selected) which you can use to define your lines.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [June 21, 2019, 12:14am UTC](https://forum.dynamobim.com/t/looping-through-a-list/37389/10 "2019-06-21T00:14:47Z")

</div>

Also your list structure is different then I originally understood the problem. You may need to use another method here. Line.ByStartPointEndPoint with @L2 on both inputs a s cross product lacing may be the way to go.

---

<div class="post-metadata">

**Author:** ![hle](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hle](https://forum.dynamobim.com/u/hle)\
**Post date:** [June 21, 2019, 3:52pm UTC](https://forum.dynamobim.com/t/looping-through-a-list/37389/11 "2019-06-21T15:52:19Z")

</div>

I have tried that but the lines drawn in that method are not correct, I managed to get the lines to draw correctly but this requires me to use the “List.GetItemAtIndex” node for each of the lists, is there anyway for me to accomplish the same result without making “List.GetItemAtIndex” node for each item on the list? Attached is my script taking a look at it may make what i’m trying to accomplish more clear

[Adjacent measure v9.dyn](https://forum.dynamobim.com/uploads/short-url/mop3NH83fsEYWDE5r0VT7dvPbjP.dyn) (61.9 KB)

---

<div class="post-metadata">

**Author:** ![hle](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hle](https://forum.dynamobim.com/u/hle)\
**Post date:** [June 24, 2019, 6:37pm UTC](https://forum.dynamobim.com/t/looping-through-a-list/37389/12 "2019-06-24T18:37:14Z")

</div>

I think I narrowed the problem down to an error with the “Line.ByStartPointEndPoint” node that says “Unable to create line. points are likely coincident” I have the “Line.ByStartPointEndPoint” node lacing set to Cross Product but it is not lacing it like that for some reason, any suggestions on how to solve this error? any help would be much appreciated.

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

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [June 24, 2019, 8:06pm UTC](https://forum.dynamobim.com/t/looping-through-a-list/37389/13 "2019-06-24T20:06:37Z")

</div>

I’m guessing you need to use list levels. Are you wanting the points in both matching sublists to create lines?

---

<div class="post-metadata">

**Author:** ![hle](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hle](https://forum.dynamobim.com/u/hle)\
**Post date:** [June 24, 2019, 10:37pm UTC](https://forum.dynamobim.com/t/looping-through-a-list/37389/14 "2019-06-24T22:37:51Z")

</div>

I tried using both list levels and lacing but neither seem to work, yes i want to use the points in the matching sublists to create lines with Cross Product lacing, but when I use Cross Product it uses points from all sublists instead of just matching ones.

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [June 24, 2019, 11:07pm UTC](https://forum.dynamobim.com/t/looping-through-a-list/37389/15 "2019-06-24T23:07:30Z")

</div>

Sometimes it’s best to just make your list structure work for you.

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

---

<div class="post-metadata">

**Author:** ![hle](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hle](https://forum.dynamobim.com/u/hle)\
**Post date:** [June 25, 2019, 2:39pm UTC](https://forum.dynamobim.com/t/looping-through-a-list/37389/16 "2019-06-25T14:39:36Z")

</div>

Thank you so much, it worked!
