Inserting new items on data tree_first and last

Hi All, i’ve searched around on the forum on the on how to insert items but i can’t just wrap my head around it. as the title, how can i add items on first and last?

Thanks!


Data Tree_insert help.gh (46.8 KB)
BFC_PointAtLines.py (532 Bytes)

Here’s one way… You are not trying to add items in the first and last items in the data tree, but in the first and last positions/indexes of each list in the tree.

You have to match the paths, and that can be done by grafting the 2 lists of items you want to insert.

I didn’t look at your whole file, so I’m assuming those 2 lists have 1 entry for each branch in your primary tree.

I’m also interested if there are other solutions.

1 Like

1 Like

thank you guys for your help, i wanted to see how to solve it via grasshopper so i can see the logic when i script it, i got it working

import Rhino.Geometry as rg
from Grasshopper import DataTree
from Grasshopper.Kernel.Data import GH_Path


tree = DataTree[rg.Point3d]()
path_count = 0


for line in LINES:
    new_path = GH_Path(path_count)
    start_pt = line.PointAtStart
    end_pt = line.PointAtEnd
    tree.Add(start_pt, new_path)

    for val in MOVE_VAL:
        pt = line.PointAt(val)
        tree.Add(pt, new_path)

    tree.Add(end_pt, new_path)
    path_count += 1

initially i only built the data tree for the mid points, i realized i can alredy include the start pt and end pt on the loop. thanks again for the idea!

2 Likes

thank you! I based my code on how @rajeev_pulari did it. Initially i came up with the same workflow as yours but thought its too long for i thought was a simple output i wanted to achieve

2 Likes