Rhino 8 Feature: ScriptEditor (CPython, CSharp)

It is great! Waiting for the next WIP release, thank you :slight_smile:

@sergey What does this return on your machine? Which Windows are you using?

import locale
print(locale.getlocale())

on my machine it is ('English_United States', '1252')

Yes, same issue here.

This appears to be an issue for more people

@eirannejad
I am using windows 10. My locale is ‘Dutch_Netherlands’, ‘1252’. I can run panda’s outside of the Rhino coding environment fine, so it does appear to be Rhino specific?

1 Like

Oh I see. So locale.getlocale() is returning en_US despite of your system locale. Interesting. Let me look into this more

Ticket is here: RH-73849 missing locale.py in importing the pandas module

@eirannejad My locale is English_UnitedStates as well. And I’m running Windows 10. Also, Pandas works fine on my local interpreter.

image

1 Like

@enmerk4r @Wilfried What happens if you set the locale manually before importing pandas

import locale
locale.setlocale(locale.LC_ALL, 'en_US')

import pandas

Does this resolve the error in importing pandas?

The issue seems to also be related to Issue 43115: locale.getlocale fails if locale is set - Python tracker

I’m still investigating to see how does Rhino environment affect the locale

Manually setting the locale to en_US did seem to solve the issue, Pandas was successfully imported.

However, I am now unable to run Scripteditor, as Rhino crashes the moment I try to open the editor. Might be unrelated though? Rebooting did not solve it.

RhinoDotNetCrash.txt (1.9 KB)

seemingly unrelated. Are you on the latest WIP? Error is referring to an Eto issue.

Thanks for the crash report. Looking at it right now ( RH-74169 Script Editor crash on open)

1 Like

Worked for me as well. Interestingly enough, my first attempt at adding Stable Baselines 3 to this equation failed with the “No module named stable_baselines3” error. Then I closed and reopened Rhino, ran the exact same code and it worked. Just FYI:

I’m not sure about windows, but on macOS it helped me with something like
$HOME/.rhinocode/python3.9-27/python3.9 -m pip install <package>.

This is not surprising as you explicitly specify the interpreter for which you are installing dependencies. Then these dependencies can be imported inside Rhino & GH.

Ya I do have a ticket for that. The bug is a little deep in the wrapping library so I’ll get to that after I’m done with the ui changes soon RH-68940 RhinoCode cpython sometimes failes to import a package it just installed

1 Like

@sthv There is only one interpretter in Rhino and that is CPython 9. You should be able to install the packages but specifying them in the script as shown in the script examples.

Installing it manually from command line into the .rhinocode directory might cause conflicts.

I’d really appreciate if you can update us about any of the packages that can not be installed from the script

It’s simple. I don’t know how to pass additional pip options using your method. I might want to install a package from a private repository, use a proxy, and so on. The existing method does not implement an full pip api or I couldn’t find the relevant documentation. But yes, of course, manually installation from shell might cause conflicts and I don’t recommend using it in any way, especially if you’re not really sure what you’re doing. It’s just that in my case it’s worked quite well so far.

1 Like

Hi why doesn’t can using Grasshopper ;in scriptEditote

Since December, I have been having an issue creating geometry with the ScriptEditor in Grasshopper.
Here is a minimal working example that works in the ScriptEditor in Rhino:

import rhinoscriptsyntax as rs
rs.AddPoint(0,0,0)

But in Grasshopper this results in the following error:

rc = scriptcontext.doc.Objects.AddPoint(point)
AttributeError: 'ILegacyDocument' object has no attribute 'Objects'

This was working earlier last December, so I thought it might be a bug.

1 Like

@Rh-3d-p Grasshopper is only accessible in Grasshopper script component. Do you have a use case that you’d want to use it outside of GH environment?

@Brendan_Harmon Oh I see. Thanks for reporting this. I have filed as RH-74259 and will take care of soon

No but i need usenew DataTree<geometry >for fast result (replace it for

LIST<List>(List) and It does not put the result in Gh _components

@Rh-3d-p Okay. Add this line to the top of your C# script:

// r "Grasshopper"

This means that you would want to reference Grasshopper.dll in your script.

Here is an Example:

// r "Grasshopper"

using System;
using System.Linq;
using Grasshopper;

var dt = new DataTree<int>();

Console.WriteLine(dt.Branches.Count());
1 Like