Ladybug/Honeybee datatypes are converted when input to Py3 component

I want to input a list Honeybee ConstructionSets in a Python 3 script to manipulate them. However, when I check the type of the input it is no longer <class ‘honeybee_energy.constructionset.ConstructionSet’>, instead it is type <IronPython.NewTypes.System.Object_3$3>. What gives? Is there any way I can work around this?

@chojje, can you provide a sample? I haven’t used the new Python Editor but if you provide an example other people on the forum including @eirannejad should be able to help.

1 Like

Assuming this is in Grasshopper: I don’t think you can pass the Python2 objects to a Python3 script component successfully like that?

While it is possible to pass simple objects between the different interpreters and rebuild them from the ".dict", I think something like a ConstructionSet would require a fair bit of work to translate over between environments, no?


1 Like

Thanks, Mostapha. Here is a sample file for testing. (17.2 KB)

My workaround currently is to pass the object through a Python 2 component which enables conversion to a dictionary which can then be passed into Python 3.

Hi @chojje,

Try to change the output type to No Type Hint and see if that resolves the issue.

Thanks for the input, it didn’t work however. The issue is that once the Py2 object enters the Py3 script, it has lost the class information created in Py2 (in the Honeybee component).

Did you also set the input type to No Type Hint? I get a different error on my machine for not being able to find the path to honeybee which I’m too lazy to edit right now.

Ah, indeed, you need to add some code for Py3 to find the Ladybug Tools path. Changing the type hints does not seem to work - I think @edpmay is onto something when saying that passing objects from Py2 to Py3 does not play very nicely.

Right, the ‘old’ Py2 and the ‘new’ Py3 are completely different interpreters, and so passing objects between them is not recommended, nor simple, as far as I understand. (Note also that there are now, in Rhino 8, TWO distinct Py2 environments/interpreters as well: an ‘old’ one using the ‘GhPython Script’ component and a ‘new’ one using the new ‘IronPython 2 Script’ component)

If you really wanted to pass objects between environments like that, I would suggest:

a) ensure that your ‘new’ Py3 environment is setup with all the required dependencies to run LBT code (all the hb and lbt libraries). When you install LBT right now I believe it only sets up the ‘old’ Py2 environment - so you’d have to manually setup your Rhino Py3 environment yourself. As far as I understand, there are currently at least 5 distinct ways to do that using the new Py3 tools in Rhino 8. Though probably #2 or #5 would be the right one(s) in this case?

b) Serialize the HB objects from your Py2 component (HB Object To String)

c) hand over the serialized data (text) from the Py2 to the Py3 components

d) de-serialize the object within the Py3 component, such that the object is loaded into the ‘new’ Py3 environment

I would guess this would be the only reliable way to make this work in a scenario like this, and FWIW is the method we use when we want to make use of other (non-Rhino) external Py3 interpreters to operate on HB objects for one reason or another.

I’m not sure what operations you need to perform on the objects that require Py3, but in most cases I’d suggest sticking within the ‘old’ Py2 environment unless you absolutely can’t for some reason. All sorts of weirdness and unexpected behavior may arise when serializing individual objects like this within a GH script - so for the most part I’d say to avoid the Py3 components.