Split list of coordinates into several branches

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.

Thanks

171220_demo_GH.gh (9.0 KB)

Use the Partition List component

1 Like

Partition

Yep! just like this…

1 Like

or with Path Mapper

1 Like

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 ?

171220_demo_GH_v2.gh (15.5 KB)

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.

you mean one specific branch from your tree?

1 Like

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.

Thanks a lot for the answer Raul !

I hadn’t thought about this feature, flexible indeed ! (and thanks for your amazing job throught those years)

Here we go with one slider…

Partition.gh (8.1 KB)

You can easily simplify the input tree of TreeBranch component and go through different branches with the slider.

1 Like

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.

please post your gh file

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:

I would first create a list of lists in python, then go through each list and create a polyline:

you can also one-line the polyline creation:

last thing, because you want the python List of Lists to become a data tree and not look like this:

you can use ghpythonlib to easily transform a python_list_of_lists into a gh_data_tree:

3D Monopitch v05_inno.gh (22.2 KB)

1 Like

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.

1 Like

in GH you can use Flip Matrix component for that:

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 :+1:

3D Monopitch v05_inno2.gh (18.3 KB)

1 Like

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?

* star operator, in this case unpacks

1 Like