Delete last X items in tree (not branch)

Hello,
How to delete the last X number of items from the entire tree, regardless of which branch it falls, while keeping the tree structure (without flattening)?

delete last items in tree.gh (16.0 KB)
Thanks,
Hanan.

But your list of points is flattened, no branches at all :interrobang: Poor data set for the thread title and description. Hidden wires are useless. What does Point Groups have to do with this?

It is a small part of a large code that I am updating, but the point of the grouping is to collect the closer points into a separate list in the tree. this is similar to the structure I have in the code.
Now I wish to reduce the number of elements, for example, to 1125 (from the current 1150), but I want to reduce the extra 25 (for example) from the end of the tree while keeping the structure as it is. I cannot do it before the grouping in the full code.
Is that clearer?


Just to explain- I want at the end to remove the last items in the tree. Here I shifted the tree and split the list, leaving the number of items I wanted, but I lost the structure of the points… maybe not so elegant solution could be to use a point group again, but must be a more elegant way, right (:?

This code deletes the last branches in the tree, which isn’t quite the same as items.


delete last items in tree_2024Aug7a.gh (25.9 KB)

As you can see in this image, if the number to delete is 30, 5 items must still be deleted from the last branch.

delete last items in tree_2024Aug7a2

1 Like

Here it is? The colored points are removed.


delete last items in tree_2024Aug7b.gh (26.8 KB)

1 Like

Looks promising (: Thanks!

Hi Bensho
Here is another solution. Maybe a little simpler. Also, It will preserve the Data paths as it was inputted. You just need to graft the tree and delete the last N branches that you want. Then use the Shift_path to return to the original structure.


Delete last items in tree.gh (21.3 KB)

4 Likes

Thanks it seems to work fine!

Oh, that’s simple and really cool and smart use of Graft.
And I managed to keep the deleted points as well.
Cheers, Daniel. Thanks.

1 Like

I was going to say that keeping the deleted points might be easier with @Danial_Keramat’s solution. :+1:


delete last items in tree_2024Aug7c.gh (18 KB)

1 Like