Grasshopper DataTree IronPython to Python 3 error

I’m trying to copy-paste an IronPython script into the new Rhino 8 Python 3 Script editor but getting the below error when working with GH’s DataTree class. Any help or clarification would be much appreciated!

The CPython implementation probably doesn’t have the object type (i.e. that IronPython does, it being .NET). So you will either need to use an IronPython scripting component, or more explicit DataTree types (e.g. imported from Grasshopper.Kernel.Types).

1 Like

Could you elaborate on how these Grasshopper.Kernel.Types might work? Do they relate to the Type Hints you can set for a scripting component’s input? I think I am misunderstanding their functionality…

Guessing here, but instead of object you could try import System and then use System.Object for the DataTree?

4 Likes

The data type within the DataTree[object]() square brackets defines the data type that the tree is allowed to contain. If we set that to object, we can add (almost) any data type. Since most .NET objects ultimately inherit from System.Object. Meaning that one can declare a more explicit type (e.g. Grasshopper.Kernel.Types.GH_Curve) if one only wants to have certain types in the data tree.

Edit: In your case, you need to wrap your PolylineCurve in a GH_Curve before adding it to the tree. But if Nathan’s suggestion works, I’d go with that. You might also try DataTree[PolylineCurve]() and skip the middlemen. Not sure if that’ll work though.

1 Like

That’s what I would try too.
The difference between IronPython and Pythonnet with CPython is that IronPython is an implementation of the Python language in .Net language whereas Pythonnet is a “translator”.

Therefore IronPython had a bunch of convenient type equivalence and I wouldn’t be surprised if Python’s object is equivalent to .Net’s System.Object.

Now, looking at your code, there are lines where object = <something>. This is a very bad idea.
object is a built-in class. If you assign another value to it, the new value shadows the built-in class. Instead do obj = <something> so that object still means what it’s supposed to.

1 Like

Thanks for the help! Much appreciated. The below seems to work as expected.

2 Likes