Looping through a list

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!

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

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.

1 Like

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

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.

1 Like

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?

List levels likely. Try @L2.

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

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.

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.

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 (61.9 KB)

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.

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

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.

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

Thank you so much, it worked!