Remove last in list based on branch number

Hi all,

I’m trying to write something that removes the last item from various different branches, but am finding it difficult. I’m not quite sure ho
w to go about it as the number in each branch could be different each time.

Sorry that I’m not really explaining this very well but I’m still trying to figure out branches. I basically want to remove the top surface from each of the three stacks. I’ve managed to simplify and split into the three piles, but now I’m not sure how to remove the top item…

Thanks in advance for any help!

Remove last (18.1 KB)

To remove the last item in each branch, use Cull Index with an index of -1.

1 Like

Or Shift List with ‘W’ (Wrap) input = False. (20.7 KB)

1 Like

Thank you guys, both approaches work as I’d like.

I feel like this is a very simple fix so feel kinda silly asking, but how do I now take this list of untrimmed surfaces, minus the last, and bring them back in as actual geometry the same as they started? As I mentioned I’m sure it’s incredibly simple to do but I’m just not seeing it…

Why don’t you apply “graft” at the final output anew?

Hi @stu92,

It is not clear what are you asking?

Do you mean baking gh geometry into Rhino? If that’s the case just right-click on the component and select “bake” (see image below), otherwise try to explain yourself a bit better.


Sorry for not being clear, my Grasshopper terminology still isn’t great!

Basically I have a Geometry component that contains the surfaces, which in this case represent floor slabs. I am wanting to essentially create a copy of this component, but without the top most element in each branch so that I can then feed it into a different script. I am not looking to bake the surfaces, I merely want to be able to see the reduced piles as a grasshopper element and not just text within a panel.

Hope that made things a bit clearer!

Ok so I was being a bit slow and hadn’t been turning previews back on! I can now see the planes manifested as grasshopper objects, except the bottom plane is the one being removed. Is there a way to reverse the order of the branches so that it removes from the other end?

Alternatively, if there is a cleaner way to carry out this seemingly simple procedure, I’d love to hear it please!

I think there were two flaws in yesterday’s code:

  1. The PShift ‘O’ (Offset) was “+1” instead of the default “-1”.

  2. Shift List was removing the first item ("+1") instead of the last ("-1).

Simplify was superfluous (as it usually is).

As @HS_Kim said, you can graft the output of Shift List to get the same data tree structure you started with. (22.5 KB)

P.S. I hadn’t even bothered to look at the geometry until you mentioned turning previews back on… Now that I have, I’m really confused??? I see three stacks of surfaces but…???

AHA! Now I can see it. If you want to remove the bottom of each stack, you need to remove the first branch of the tree after PShift: (33.6 KB)

1 Like

Hmm, I’m still not getting the correct output, and I think it’s maybe because I’m not understanding the hierarchy of the branches properly. I’ve downloaded your script Joe, but I’m still not having much luck. Rather than remove the top surface as indicated in the image of the original geometry, it removes an entire stack.

Any ideas?


See above. Each branch of the tree (after PShift) is one layer of all three stacks. You can see that branches {4}, {5} and {6} have only two surfaces because the short stack has only four layers while the others have seven.

The Split Tree ‘M’ (Mask) input is a little fragile as it will break if the data tree changes; perhaps a good place to use ‘Simplify’, or maybe a wildcard? (32.8 KB)

1 Like

While not getting the exact result I was looking for, that last script was very helpful for me to get my head around data trees and branches (and also masks which I’m only just learning about), so thank you! For now I’ll just need to settle with something a little more simplistic that evaluates each size of stack individually.

What’s wrong with it? Do you want to remove the top item in each stack instead of the bottom one? It sure would help if each stack was one of three branches in a data tree, which is what the earlier Shift List version assumed.

Sorry if I hadn’t been explicit. Yeah, it’s the top item that I am wanting to remove. I thought the issue was as a result of each stack having different numbers of items, not my poor communication skills.

I added an extra layer of filtering into your last script to take the top item from the largest script, and then select the specific item from the shortest list. Isn’t perfect, but it’s getting there.

Yeah, that’s pretty ugly, isn’t it… I’ve struggled and failed so far to organize the stacks into three branches (one list/branch per stack) instead of seven branches (one list/branch per layer). Very tricky! :frowning:

Oh well, that makes me feel better that I wasn’t just being stupid at least.

I honestly think that these stacks/blocks of slabs should be constructed in a different way in a very beginning, so that later on it would be possible to gain proper control over data structure. Here is an example below, not necessarily the best way, just an example. (15.8 KB)

ABSOLUTELY RIGHT!!! The yellow group below goes to insane lengths to re-organize them: (40.8 KB)

Much easier to do it earlier in the code than to cope with a data tree like @stu92 gave us here.

1 Like

That looks infinitely easier, thanks for the advice. I actually inherited the data tree from someone else and so wasn’t involved in the original structuring of it, but in future will be sure to try and keep things as simple as possible from the outset.