Partial flatten tree

Hi! I am trying to partially flatten a tree but, I have trouble understanding it from Rhino’s documentation. Could someone please share some guidance?

Input: tree in the form {k:0:0}, {k:0:1}, {k:0:2}, {k:1:0}, {k:1:1}, {k:1:2}
output: {k:0}, {k:1}
In other words, I only look at the second-to-last index, combining branches sharing second-to-last index into one branch. In the above example, {k:0:0}, {k:0:1}, {k:0:2} becomes {k:0} because they share 0 as their second index. This reduces the dimension of the list by one.

What I know: how to get the {x:y:z} ‘indices.’ This allows me to look through {k:0:0}, {k:0:1}, {k:0:2} and put them in a jumbo-list for {k:0}
What I don’t know: how to return the new tree I’m returning (In the above example, I have dimension = 3 tree, but my output is dimension = 2 tree.)(I’m confused)

Thanks a lot!

For example: I got 4 groups of (3 separate) lines (so 3 lines per group), and I want to extract the control points. But the control point function makes it so that, I get additional dimension

resulting tree is: ‘number of groups : number of lines per group : number of control points’) (useless for my particular purpose)
what I want: tree of the form ‘number of groups : total number of control points (summing up for all lines in this group)’

This kind of adding-dimension-by-force happens to other modules too, and I don’t know how to fix

You could use Path Mapper, but Shift Paths or Trim treeshould work as well…


PathCollapse_re.gh (14.1 KB)

2 Likes

Thanks so much HS_Kim! These are all great solutions.

If I don’t know the dimension of the input list (could be {a:b:c:d:e}) but know that I just want to reduce the last dimension (e dimension in this example), would Shift Paths and Trim Tree be better? (It seems Path Mapper needs to know the dimensions of the input and output of the trees. I’m also testing this out