Help: Select first & last lists in each primary branch

In my example, I will have 1 or more collections being entwined and require the ability to select the first and last list of each collection as shown in the example:


this file attached.
first-last-branch-selection.gh (139.8 KB)

Deconstruct the paths, create the set of the first branch path indices and use this to extract the second branch path index. Get the first and last item of both lists of branch path indices and construct paths.

It can be done a bit simpler…

first-last-branch-selection.gh (145.8 KB)

1 Like

Thank you Martin.

1 Like

Here is a python option:
first-last-branch-selection_v1.gh (154.3 KB)

1 Like

In continuation, I now have processed the data I needed, and I need to insert the new items at the start and end of the starting tree.

I’m looking for a Grasshopper (non-code) solution please.

insert-first-and-last-branches.gh (185.1 KB)

Yes but I’m away from my computer for a few hours now.

Thanks. I’ve simplified the the definition further. I will try to come up with a solution and will update the post if I figure it out.

Here’s a simple version to insert at front and back.
I’m basically reducing the level of the tree to be able to insert both at front and end of the lists, and then recreate the “original tree structure”.

This works as long as all the the branches have the same number of items (in this case 2).
If it becomes more than two, simply change the panel that has 2 in it, or make it dynamic by checking the length of one of your list. (let me know if this isn’t clear)


insert-first-and-last-branches.gh (195.7 KB)

Thanks for this, but I changed the definition before you posted it. Please see this:

There you go


insert-first-and-last-branches (1).gh (191.0 KB)

Since you merged your trees, I felt like doing a tree approach to the problem.
Im basically changing the branch indexes of both trees so that i can simply merge them together at the end.

1 Like

That works exactly as intended. do you know if something like this would be possible to do with Path Mapper?

I keep forgetting about that component because it lacks (IMO) some lexical operations (if that’s the correct word).

Although path mapper can be used for the upper part of the definition, I don’t think it’s possible to use it for the one below. But I could be wrong on this.

Ah… I’m getting somewhere but not quite yet.
But at this point, it gets more complicated than Gh or a python component.

So I can’t, but as it happens, chatGPT4 could… damn I need math refresh.

Behold the pathmappermonster :space_invader::


insert-first-and-last-branches (2).gh (182.9 KB)

Edit: Since these are exponential functions, GPT warns you that the index of the branch should not go above 700, what a nice guy (actually I had to ask him about it).
The Grasshopper version shouldn’t have a limit.

1 Like

LOL. I think I prefer your grasshopper component solution better :slight_smile: Thanks for the extra effort.

1 Like

You can also use wrap data to help in this situation, as you can approach a data tree as a list instead:


Way easier if you ask me :stuck_out_tongue:

@Brett_Abroe true, but requires an additional plugin.

Ah right - didn’t realize that was a requirement. Metahopper is a plugin that I would highly recommend as an essential

I do use metahopper, but I try not to mingle too many plugins in my logic. I will use for non-critical stuff like manipulating the canvas and other objects, but will not use it to manipulate data.