Data Tree > What Data Type for Generic Data?

Newbie Python scripting question (working on a geometry import/ export script for a Grasshopper project)
I’m creating two data trees in the same Python script: one for generic geometry and one for generic data (like integers, floats, strings).

Rhino.Geometry.GeometryBase works for generic geometry types:

myTree = DataTree[Rhino.Geometry.GeometryBase]()

But what data type do I declare for data like the following?

(5, 2.0, 3.0, 'point')

Thanks,
Ole

I am noob myself and don’t really understand DataTrees yet but this doesn’t trigger an error so… :stuck_out_tongue_winking_eye:

@ivelin.peychev Thanks! I’ll give that a try.

1 Like

@Ukko,

Let me know if it works, I was a guess.

@ivelin.peychev It worked like a charm :grin:

I used the string version of your suggestion:
nameTree = DataTree[type(str())]()

where the data looked something like this:
name = (5, 2.0, 3.0, 'point')

…and added to the tree like this (converting the above to a string):
nameTree.Add(str(name),myPath)

FYI, The export script I made custom names ‘sets’ of objects. The name of every object in each set begins with the same number. When importing the objects I use that number to add those matching objects to the same tree branch. Basically I’m exporting/ importing groups without having to use groups.

The exported object name also contains other useful data about the objects besides what set they belong to that was generated in the Grasshopper file that created them. Bringing that data in through the import process saves me having to regenerate the information in the new Grasshopper file.

Thanks again for your help.

1 Like

Hi Ukko,

You already solved your problem, but in order not to pay attention to the type of data that you add to the DataTree, you can use the “object” type:

import Grasshopper

dataTree = Grasshopper.DataTree[object]()

nameL = (5, 2.0, 3.0, 'point')
myPath = Grasshopper.Kernel.Data.GH_Path(3,100,5,1)

dataTree.AddRange(nameL, myPath)

Old forum has plenty of useful examples.

1 Like

@djordje That works even better for my particular use. I was able to structure the data exactly how I wanted. I didn’t know about the .addRange method.
There’s a lot of great information in the links you provided.
Thank-you.