Hello,
wan
I’m trying to split a list into several (and regular) branches, solutions found on the forum apparently doesn’t work, probably because this list is coordinates..
So I’m trying to divide those coordinates into regular branches each 4. Here’s my attempt and what I would want.
Wow thanks, can’t believe I missed it ! Partition is better than Path mapper in my definition, because the number is subject to change due to precedent parameter, thanks a lot !
And, while I’m at it, what would be the best way to retrieve one branch of the tree ? (with all 4 coordinates) Basically I need the list item for subset, but the “Sub list” component isn’t working, how should i input the domain properly to get those points ?
Partition is also quite flexible as it can handle differently sized sublists. You could partition it into chunks of 4 points, then 2 points, then 1 point, then 4 points again and repeat.
Yes exactly, but I would need to have a slider to chose the domain, any ideas ?
So a slider that would pick (0;0) then (0;1) then (0;2) and so on…
To make it a bit clearer to you I’m recording and extracting iterations from a Kangaroo component, and I would need to see the all process going on with one slider.
Just coming back to this topic after eight years, I have the same problem only I’m trying to split a list of coords in python. I’m using the ghpythonlib.components and I’ve tried the partition method but it leaves the list unreadable as coords so I’m not able to add a polyline through them. If I output the same partitioned lists from the python node I am able to draw the polyline with them on the canvas. I’ve tried the treehelper method of converting them back to lists but still no joy.
The split method in ghpythonlib - it’s difficult to pick either the list A or list B as output so I’m not sure if this would work but I suspect not.
inno,
please find enclosed a paired down file. I’m attempting to partition the final list (Col_Coords) and you’ll see I’ve tried two methods. When the addpolyline component is turned on then you’ll see the error. 3D Monopitch v05.gh (17.7 KB)
as a Python noob myself -but devoted student- (so take this with a pinch of salt…) I think it’s easier if you work with Lists and Lists of Lists, then you transform data into grasshopper data trees only at the very end
so here, instead of creating a tree, which is fine for gh but a tad more laborious to access further in python:
That’s absolutely super, inno. Your lines 51 and 56 have just enhanced my understanding of python grammar.
I’ve now got an afternoon ahead trying to link corresponding column points horizontally!
Many thanks.
in Python you can use list comprehension like this to create a List where points are organized horizontally (first list contains all the first points of each list, second list contains all the second points of each list and so on… [p.s. this assumes all your lists have same length] )
then draw a polyline through each list of point (exactly the same as for the vertical ones, points are arranged differently but same principle) and finally output stuff as gh data tree
the two outputs indicated by the red arrow contain the very same data but, because gh_Flip_Matrix operated on a data tree with branches, the output is still a data tree with a single polyline on each branch
while for the Python output, we just created a single list and spit all the polylines in that very same container, so they lie all in the very same branch
That’s brilliant! I’d not known about the method of reading across lists to make another list nor the zip function. What does the * do in line 58 before the Col_Coords_A?