Last Sub-branch Selection in a Data Tree

Is there easier way to select last subBranch. Or its always jumping through hoops?
With split tree its nor problem get first subBranch.
But there no such shortcut for the last subBranch.

Here simple example:

lastSubbranchSelection.gh (23.5 KB)

This post by @DavidRutten has been shared a few times already…

image

DataTree selection rules - Grasshopper

One thing you could do with less components is unflatten the list of paths and extract the last item:

lastSubbranchSelection.gh (26.9 KB)

Cool beans. Would have attempted this wih Partition List.

Why do I always forget Unflatten Tree exists?

I see last item from path list! That’s much more readable and concise logic.

Maybe there should be a component to reverse tree :thinking:?
To work in tandem with Split Tree if rule -1 is not possible in DataTree path filtering.

lastSubbranchSelection.gh (27.4 KB)

Path Mapper?

Hmm, I dont think so.
Seems like PathMapper sees total branch count, so it would work for one level tree and reverse it succefully.
But if second branch level added PathMapper does not differentiate and does not know count of e.g.{2;*} branch.

—

EDIT
Seems like pathMapper works same way as treeBranch with renumber.

Some solutions. Are they useful? :person_shrugging:


lastSubbranchSelection VR 1.gh (48.7 KB)

Mostly work-arounds to not being able to use -1 in a path mask. #yetAnotherThingThatWon’tBeChangedOrFixed

Interestingly, you can’t use -1 for Split List either.

I usually do it this way

@Edr I feel like the solution in your opening post is the best one, even if it is longer, because it doesn’t assume any previous knowledge of data structure (having to reach back to the Circle component)

the “-1” connected to Wrap instead of Index is a typo or is intended?

It’s a mistake. The index input has ‘-1’ internalized. When I did the screenshot I thought someone is going to be confused so I typed ‘-1’ into a panel but connected it to wrap instead.

Ok thanks for clarification
Since index is 0 by default, when I want the last item I usually do this to mantain readability and minimize elements on canvas

Yes that is a clean alternative

All ways seem like solution :slight_smile:

So here is file containing all of them

lastSubbranchSelection 2.gh (31.9 KB)

You should be able to set path depth with the scripting component.

Its possible, but I feel it gets fuzzy/complicated on larger Data Trees and many edge cases should be resolved. What is the last branch at different path depth? What if Data Tree paths are not of equal length?

In first post It seemed there should be simple solution to selection, but now I believe it should be tailored to specific use case.

Should Tree be trimmed or not when selecting?

LastBranchSelection

Nice.

So, firstly, your depiction captures the idea but is wrong in the sense that a branch always starts at the root.

@Edr edit:



Depth of zero would be the whole tree. It’s a little confusing with the depth integer. Here I’m interpreting it as it is with Shift Paths, where it is like an offset number. The discrepancy is that then the depth integer is the x+1 path item for positive values.

Secondly,

This sounds a lot more complicated than it actuallly is. The Depth integer simply denotes up to which depth the last sub-division branch algorithm is applied, after which all sub-dividing branches are taken.

I am uncertain of what this means. Probably untrimmed. You deal with the branch addresses / paths as they are given to you, and any trimming is an external action that is the responsibility of the user.

heh, made some vibe slop component.

—
Plugin here, but still buggy in UI/UX

at sets → tree

DataTreeSelector.gha (32.5 KB)

Wow, cool.