Data Tree Path in Python

Hi,
I am trying to get Data Tree with custom paths. For instance, I have 5 points and each of them are named with a number(2,2,3,4,5) I want to get output as seen below:

Here is my code:

import rhinoscriptsyntax as rs
import Grasshopper.DataTree as dt
import Grasshopper.Kernel as gk
import Rhino as r
import scriptcontext as sc
sc.doc=r.RhinoDoc.ActiveDoc

plist=[i for i in x]
tr=dtr.Geometry.Point3d
a=[tr.Add(i,gk.Data.GH_Path(2)) for i in x]
sc.doc=ghdoc

Thanks in advance.

This might help you getting the hang of reading and writing datatrees:

Edit: and this of course:

I tried “treehelpers” and I could manage to get trees out of the lists, however I am trying to use rhinocommon to enlarge the manipulation possibilities over the trees. I have read those documents you suggested, thank you very much for that, but I could not manage to succeed. I don’t know where am I doing a mistake on this code.

I think your issue is when you are assigning the output variable a. As the DataTree.Add() method does not return anything, in line 20 you are assigning a to a list of None.

You’ll want to use the tree itself as an output of your component, or assign a = tr.

1 Like

Thank you very much for the help, it is an annoying mistake there I did. Solved.