No module named 'System.Drawing.Color' in Rhino Code Editor

Hi, I am playing around with a few of my old scripts in the new Rhino Code Editor on the Mac. I have a colour gradient maker that works when run through the old Tools>PythonScript>Edit , but when I run through Rhino Code it tells me

Python.Runtime.PythonException: No module named ‘System.Drawing.Color’

Does anyone know why this would work in one but not the other?

Thanks

System.Drawing is not really cross-platform. You can use Eto.Drawing, defining an own color struct or you use a 3rd party library.

Thanks Tom, I didn’t know about ETO, thankyou. ETO looks like it is C#, VB, F#, will the syntax work with Python?

We have our own version of System.Drawing.Color working on Mac. If you have a script that used to work and is now not working, please share it with us. @eirannejad is actively working on this project and we do expect a few bugs to show up during the transition over to Rhino Code.

1 Like

Thanks.

Yes, because Rhino ships with Eto as a cross-platform GUI framework (wrapper). Also, you are coding in IronPython (C#/Net written Python) not CPython! This is something you should be aware of. So the answer is definitely yes!

Hi @stevebaer and @eirannejad , I have attached a Cairo Tile gradient script which uses System.Drawing.Color
I’ve included the rhino file to compare running both ways.

MkngCairoTile.py (8.7 KB)
Sandbox.3dm (2.1 MB)

@Chris_Bamborough Change the import System.Drawing.Color to from System.Drawing import Color

What is in front of import should be namespaces (usually match the name of containing DLL). In this case Color is a type in the System.Drawing namespace

For odd reasons import System.Drawing.Color used to work in IronPython but it is an invalid syntax in Python 3

2 Likes

Thanks Ehsan, I originally found out about System.Drawing from colleagues, but now that I’m coding on my own I don’t have an API reference to understand what it can do, does one exist?

1 Like

Have a look at the .NET documentation:

1 Like

Seems to be rather correct, because “System.Drawing.Color” is no module, but a struct inside the System.Drawing library/module. Maybe old IronPython supported that inaccuracy, since whats considered a module in Python and C# is a fundamental difference and shouldn’t be threaded as the same. In Python I can put a single class into a code file and use it as a “module”. In C# a “module” rather counts as a .dll, containing multiple types in various code-files. On top of that, a .Net namespace like System.Drawing could potentially consist of multiple files and even .dll’s. In CPython, this is not even possible. So how do you deal with that if you have something like IronPython?!

1 Like

In case of namespaces that are spread across multiple dlls, I usually do multiple clr.AddReference to each of those dlls and then import the namespace