Scritping in R8, ironpython2 and python 3?

Hi.

Am working on a workflow that depends on LBT-components for calculation, as well as LBT modules for calculations inside my own python code.

I’m trying to cross over into Rhino8, mainly with regards to being able to publish a plugin fairly easily, but am starting to become a bit confused.

LBT components work in R8, and I installed via pollination.
LBT in R8 runs in the old editor, and old version of ironpython.

But moving forward, I thought it would be sensible to transition into the new editor and python 3, or at least iron python 2.

I tried moving some code from “LB Deconstruct Data” to iron python 2, processing just windspeed from epw-import, but:

Failed to import ladybug:
No module named ladybug.datacollection
IronPython.Runtime.Exceptions.ImportException:

And in python3, component, I got the following:

AssertionError: _data must be a Data Collection. Got <class ‘IronPython.NewTypes.System.Object_2$2’>.

So it seems that it cant access the data, as it is on iron python format.

Am I totally off track, and should be happy with the old editor, and older version of iron python?

Or is there something that I’m doing wrong?

Sincerily,
HappyBuddha

Hi @LittleBuddha ,

Yes the new Rhino python landscape is confusing (IMO). The short version is: you should continue to use the older GhPython components whenever you want to work with the LBT SDK or LBT objects in your Rhino/Grasshopper files.


The slightly longer version is:
Rhino & Grasshopper have 3 distinct python interpreters now; a 3.x one, an IronPython one, and the older GhPython one. These three interpreters are fully separate from one another, and while it is technically possible to pass some very simple objects between interpreters, it is not recommended, and certainly complex objects like LBT rooms, models, etc cannot be easily moved between them.

The three interpreters do not share system path or dependency environments, and so installing the LBT libraries on the GhPython one will not make them available on the IronPython or v3 ones.

Unless / until the LBT components themselves are updated to work in the ‘new’ interpreters, we will just need to stick with the ‘old’ one.


hope that helps!
best,
@edpmay

3 Likes

Hi @edpmay

And thanks for your prompt and helpful answer.

Basically hands off, don’t do it and continue to embrace iron python version 1.

Would have been nice to get access to the new editor though, when working with the components.

Some of my components are marked old, and some not. Which I also haven’t figured out why.

Yours,
Little and fairly happy Buddha

@edpmay gave the right recommended answer here.

There’s a lot of fixing and improvements to the new Rhino 8 script editor that Ehsan from McNeel has been working on for the past few years (and is continuing to work on). He has done a great job but, because of all the changes, the earliest that you will see us move the Ladybug Tools components over to the new Script Editor is Rhino 9.

So using the old GHPython component and old IronPython environment is currently the best way to use Ladybug Tools for now in Rhino 8. If you need to summon an old GHPYthon onto your canvas, just double-click it and search for #GHPython (with the #). That will let you bring it up instead of the new script component.

Also for this:

Ehsan gave us a method that we can call to turn the tag off in our old GHPython components. You should find that they are all gone from your Ladybug Tools components if you’ve installed the latest version of Ladybug Tools and run the LB Sync Grasshopper File component to update all of the LBT components on your canvas.

If you want to get the OLD tag to go away on your own custom components, the method Ehsan added into the Rhinocommon SDK is Component.ToggleObsolete(False). You can see that I wrapped it into a function we use in Ladybug Tools here:

So you can make use of it inside your own GHPython component in the following way:

from ladybug_rhino.grasshopper import turn_off_old_tag
turn_off_old_tag(ghenv.Component)

Lastly, I’ll add that the latest Pollination installers add the Ladybug Tools core libraries to the Python paths of the Rhino 8 Script Editor. So, if you use the latest Pollination installer, you should not have any more import errors if you try pasting code from LBT’s GHPython components into a new ScriptEditor component. This means that you can technically use the LBT core libraries in the Rhino 8 script editor if you want. Just beware that the environment of these ScriptEditor components doesn’t really talk to that of the GHPython component as Ed mentioned.

But there is a lot of power and potential in the new script editor, particularly for things like making your own Rhino commands with the LBT SDK. For example, the Rhino 8 ScriptEditor is how I made these Environmental Analysis commands that we have been shipping with the Pollination Rhino installer.

3 Likes

Thanks a lot to both @chris and @edpmay for their answers, the way forward is much more clear to me now.

1 Like

@chris, thanks so much for this!! As a semi-OCD I am so happy to get rid of those tags

1 Like