Construct or copy DataTree in Python

Hi all,

I have formerly mostly written in C# when working in Grasshopper, but now sometimes have to write parts in Python too, and struggling a bit with this IronPython adaption.

When construction a empty DataTree in Python, I know I can write;

import Rhino.Geometry as rg 
import Grasshopper as gh

point_tree = gh.DataTree[rg.Point3d]()

However, I now like to use another constructor for DataTree, the one that takes a DataTree as input to create a shallow duplicate. My first guess was to write it as below, but it do not work;

point_tree = gh.DataTree[rg.Point3d](other_tree)

So how do I access the other constructors of DataTree? I would really appreciate some help with the syntax here, because there’s obviously something I am not getting. Or, is there another way to copy a tree?

As far as I recall, the shallow duplicate constructor works if you set the DataTree type to object:

point_tree = gh.DataTree[object](other_tree)

You might also implement the copy.copy() and copy.deepcopy() Python functions.

1 Like

You’re right, that syntax works if I set the type to object. Good to know, I’ll go for that for now. Thanks a lot!

1 Like