# Last Sub-branch Selection in a Data Tree

**URL:** <https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989>\
**Category:** Grasshopper\
**Tags:** windows\
**Created:** [April 14, 2026, 1:14pm UTC](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989 "2026-04-14T13:14:28Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edr](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/edr/32/773223_2.png) [@Edr](https://discourse.mcneel.com/u/Edr)\
**Post date:** [April 14, 2026, 1:14pm UTC](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989/1 "2026-04-14T13:14:28Z")

</div>

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](https://discourse.mcneel.com/uploads/short-url/1Y6UcC1YO5u0Gi5KY7KpWfY2hYD.gh) (23.5 KB)

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/e/5/4/e542b350e6924f2ddc6466b230da938eb0b3a2da.png)

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/9/1/6/916d0db2dcffc988cc2fdf3423c4231c6e9c00aa.png)

---

<div class="post-metadata">

**Author:** ![martinsiegrist](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/martinsiegrist/32/772775_2.png) [@martinsiegrist](https://discourse.mcneel.com/u/martinsiegrist)\
**Post date:** [April 14, 2026, 1:40pm UTC](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989/2 "2026-04-14T13:40:27Z")

</div>

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

![image](https://global.discourse-cdn.com/mcneel/uploads/default/optimized/4X/a/7/a/a7aa66dee8fb073ee389a73a915020fe0d92768e_2_690x51.png)

[DataTree selection rules - Grasshopper](https://www.grasshopper3d.com/forum/topics/datatree-selection-rules?page=6&commentId=2985220%3AComment%3A1888369&x=1#2985220Comment1888369)

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

[lastSubbranchSelection.gh](https://discourse.mcneel.com/uploads/short-url/tXFLLvPb6Ua9XxAaWXgOQhA588O.gh) (26.9 KB)

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/e/c/3/ec393c0f1359923a7a4fe758c3b6c0f9e8bde6c5.png)

---

<div class="post-metadata">

**Author:** ![Volker\_Rakow](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/volker_rakow/32/770451_2.png) [@Volker\_Rakow](https://discourse.mcneel.com/u/Volker_Rakow)\
**Post date:** [April 14, 2026, 4:20pm UTC](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989/3 "2026-04-14T16:20:19Z")

</div>

Cool beans. Would have attempted this wih Partition List.

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/0/2/d/02d23ea55d153af3cd7baa984d5a6506bd3d7e15.png)

Why do I always forget Unflatten Tree exists?

---

<div class="post-metadata">

**Author:** ![Edr](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/edr/32/773223_2.png) [@Edr](https://discourse.mcneel.com/u/Edr)\
**Post date:** [April 14, 2026, 7:08pm UTC](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989/4 "2026-04-14T19:08:54Z")

</div>

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

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

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/c/5/2/c524f38c6f8712d63272de4992b8b1d39e7c66da.png)

[lastSubbranchSelection.gh](https://discourse.mcneel.com/uploads/short-url/hyvvhu8KxN7vqn1wV4X9ZrKl2Ni.gh) (27.4 KB)

---

<div class="post-metadata">

**Author:** ![martinsiegrist](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/martinsiegrist/32/772775_2.png) [@martinsiegrist](https://discourse.mcneel.com/u/martinsiegrist)\
**Post date:** [April 14, 2026, 7:10pm UTC](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989/5 "2026-04-14T19:10:05Z")

</div>

> [@Edr](#):
>
> Maybe there should be a component to reverse tree 🤔?

Path Mapper?

---

<div class="post-metadata">

**Author:** ![Edr](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/edr/32/773223_2.png) [@Edr](https://discourse.mcneel.com/u/Edr)\
**Post date:** [April 14, 2026, 7:53pm UTC](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989/6 "2026-04-14T19:53:59Z")

</div>

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.

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/a/2/0/a202b94bff5b2aad47639eef739603c12abbb2f0.png)

> **[Grasshopper Data Tree - Path Mapper is a BADASS](https://bimcorner.com/grasshopper-data-tree-path-mapper-is-a-badass/)**
>
> Learn Grasshopper Data tree structure, it is easy!. Check out the path mapper component and how to use it with data tree structure...

—

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

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/a/3/2/a32b599b750d105813c1750d37268a8fedefd576.png)

---

<div class="post-metadata">

**Author:** ![Volker\_Rakow](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/volker_rakow/32/770451_2.png) [@Volker\_Rakow](https://discourse.mcneel.com/u/Volker_Rakow)\
**Post date:** [April 14, 2026, 8:35pm UTC](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989/7 "2026-04-14T20:35:37Z")

</div>

Some solutions. Are they useful? 🤷

 ![Screenshot 2026-04-14 222923](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/4/f/4/4f4a16974c953b8d6d005db082bc61e688f4e9e3.png)  
[lastSubbranchSelection VR 1.gh](https://discourse.mcneel.com/uploads/short-url/lO7DkhQoTAEhPYH7DarcfVOEgMN.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.

---

<div class="post-metadata">

**Author:** ![Fabio\_Franchetti](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/fabio_franchetti/32/773331_2.png) [@Fabio\_Franchetti](https://discourse.mcneel.com/u/Fabio_Franchetti)\
**Post date:** [April 15, 2026, 9:14am UTC](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989/8 "2026-04-15T09:14:26Z")

</div>

> [@Volker\_Rakow](#):
>
> Interestingly, you can’t use -1 for Split List either.

I usually do it this way

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/0/c/1/0c18070ae695de973c437855604b59082ce8ce04.png)

---

<div class="post-metadata">

**Author:** ![Volker\_Rakow](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/volker_rakow/32/770451_2.png) [@Volker\_Rakow](https://discourse.mcneel.com/u/Volker_Rakow)\
**Post date:** [April 15, 2026, 4:07pm UTC](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989/9 "2026-04-15T16:07:26Z")

</div>

@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)

---

<div class="post-metadata">

**Author:** ![Fabio\_Franchetti](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/fabio_franchetti/32/773331_2.png) [@Fabio\_Franchetti](https://discourse.mcneel.com/u/Fabio_Franchetti)\
**Post date:** [April 15, 2026, 4:29pm UTC](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989/10 "2026-04-15T16:29:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![martinsiegrist](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/martinsiegrist/32/772775_2.png) [@martinsiegrist](https://discourse.mcneel.com/u/martinsiegrist)\
**Post date:** [April 15, 2026, 4:43pm UTC](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989/11 "2026-04-15T16:43:39Z")

</div>

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.

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/d/6/b/d6b6308090867896b0e50b5d1d311c2e6436b274.png)

---

<div class="post-metadata">

**Author:** ![Fabio\_Franchetti](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/fabio_franchetti/32/773331_2.png) [@Fabio\_Franchetti](https://discourse.mcneel.com/u/Fabio_Franchetti)\
**Post date:** [April 15, 2026, 5:16pm UTC](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989/12 "2026-04-15T17:16:28Z")

</div>

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

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/1/a/a/1aa6a36096e86e5e815176a10c49729b38f4de83.png)

---

<div class="post-metadata">

**Author:** ![martinsiegrist](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/martinsiegrist/32/772775_2.png) [@martinsiegrist](https://discourse.mcneel.com/u/martinsiegrist)\
**Post date:** [April 15, 2026, 5:19pm UTC](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989/13 "2026-04-15T17:19:18Z")

</div>

Yes that is a clean alternative

---

<div class="post-metadata">

**Author:** ![Edr](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/edr/32/773223_2.png) [@Edr](https://discourse.mcneel.com/u/Edr)\
**Post date:** [April 16, 2026, 5:50am UTC](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989/14 "2026-04-16T05:50:16Z")

</div>

> [@Volker\_Rakow](#):
>
> @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)

All ways seem like solution 🙂

So here is file containing all of them

 ![lastBranch](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/c/7/9/c798ba520c55768893c38ae28a398233c856e261.png)

[lastSubbranchSelection 2.gh](https://discourse.mcneel.com/uploads/short-url/nmKljzwoG8k7X1XSRq5HKIuhb24.gh) (31.9 KB)

---

<div class="post-metadata">

**Author:** ![Volker\_Rakow](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/volker_rakow/32/770451_2.png) [@Volker\_Rakow](https://discourse.mcneel.com/u/Volker_Rakow)\
**Post date:** [April 16, 2026, 7:20am UTC](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989/15 "2026-04-16T07:20:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Edr](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/edr/32/773223_2.png) [@Edr](https://discourse.mcneel.com/u/Edr)\
**Post date:** [April 17, 2026, 8:54am UTC](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989/16 "2026-04-17T08:54:11Z")

</div>

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?

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/f/9/9/f995d9978655b7788d4af76e8270367b3f5e6475.jpeg)

![LastBranchSelection](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/4/e/b/4ebc2fd1d5f6a2f2e1e606879a5d83cfcb9646bf.gif)

---

<div class="post-metadata">

**Author:** ![Volker\_Rakow](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/volker_rakow/32/770451_2.png) [@Volker\_Rakow](https://discourse.mcneel.com/u/Volker_Rakow)\
**Post date:** [April 17, 2026, 9:21am UTC](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989/17 "2026-04-17T09:21:15Z")

</div>

Nice.

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

@Edr **edit:**

 ![Screenshot 2026-04-17 110918](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/c/d/1/cd1f243798fd09908891f957b39358c0f011a15a.png)

 ![Screenshot 2026-04-17 114208](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/5/a/9/5a90fe60ca71c4b1acdb4927706d6ad710f5b03e.png)  
 ![Screenshot 2026-04-17 114844](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/9/a/5/9a5e89fdbdb8e727822d41c47d8311d56b5fdef8.png)

 ![Screenshot 2026-04-17 114522](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/b/8/9/b89e87bd4661ab67f155466467f70bcb6bbc98e1.png)

* * *

 ![Screenshot 2026-04-17 114844 copy](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/3/f/8/3f883528de1d960df38b2cf1bc4d4100bf65b1c5.png)

* * *

 ![Screenshot 2026-04-17 160240](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/8/f/3/8f3c91807e15ce3a5f926e5c85e041e98f50d0e5.png)

 ![Screenshot 2026-04-17 114208 copy](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/5/1/2/512ace79142fe100e6e7451d28b7f460399ce33d.png)

 ![Screenshot 2026-04-17 114522 copy](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/0/8/7/087fa3c20e8b1d5bdefc090fcfd5cac953de7514.png)

 ![Screenshot 2026-04-17 110918 copy](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/6/6/5/665f650d0aa66d307072e06b900924222ff92b7c.png)

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,

> [@Edr](#):
>
> 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?

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.

> [@Edr](#):
>
> Should Tree be trimmed or not when selecting?

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.

---

<div class="post-metadata">

**Author:** ![Edr](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/edr/32/773223_2.png) [@Edr](https://discourse.mcneel.com/u/Edr)\
**Post date:** [April 19, 2026, 3:57pm UTC](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989/18 "2026-04-19T15:57:37Z")

</div>

heh, made some vibe slop component.

—  
Plugin here, but still buggy in UI/UX

at sets → tree

[DataTreeSelector.gha](https://discourse.mcneel.com/uploads/short-url/iluSfmj35HgVmRhMYcLbajoFnoQ.gha) (32.5 KB)

---

<div class="post-metadata">

**Author:** ![Volker\_Rakow](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/volker_rakow/32/770451_2.png) [@Volker\_Rakow](https://discourse.mcneel.com/u/Volker_Rakow)\
**Post date:** [April 19, 2026, 5:35pm UTC](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989/19 "2026-04-19T17:35:23Z")

</div>

Wow, cool.

---

<div class="post-metadata">

**Author:** ![dfytz1](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dfytz1/32/478701_2.png) [@dfytz1](https://discourse.mcneel.com/u/dfytz1)\
**Post date:** [June 14, 2026, 9:24am UTC](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989/20 "2026-06-14T09:24:59Z")

</div>

Hi, can you please give a github link/source code for this?

[Next page](https://discourse.mcneel.com/t/last-sub-branch-selection-in-a-data-tree/217989.md?page=2)
