How to use Eto PixelLayout on Windows and Mac in Python script that trims mesh to curve

I have created a GUI using Eto so it can be used on both a Windows and Mac platform. In order to get the form to look reasonable with 3 controls on one line, I used PixelLayout instead of DynamicLayout for some of the controls. But I read this is highly discouraged, as each control may be different sizes based on the platform. One way of dealing with this is to just develop 2 sets of locations for the controls, 1 for Windows and 1 for Mac.

My questions is:
In my Python script, how do I tell whether Rhino is running on a Windows machine or a Mac?

Here is what the form looks like with 3 controls on the second line:

and here are some examples of using it to trim a mesh to a boundary curve, make a hole inside the boundary curve and make a trench inside the boundary curve:

The mesh has 1.4M faces and I have not been able to trim it in Rhino using Mesh Tools -> Trim Mesh without creating ragged edges (mesh faces not trimmed to boundary shape), or failing with no error message. The Python script fixes these issues, at least for my collection of meshes.


I was going to suggest

mport platform
arch = platform.uname()[0]

but it appears our IronPython is buggy in that respect.

Python2.7 on the command-line on the Mac gives 'Darwin' as the result, but Rhino IronPython gives 'Windows', which is obviously wrong…

edit: I logged to track this bug.

How about:

import sys
print sys.platform

The print say
on my Windows system.
What does it say on a Mac system?


import os 

Should give the system path separator
I think it’s \ on Windows / on Mac
It’s : here on my iPhone :wink:

On my Windows system this returns

What is this on a Mac system?

Ahh that’s not right hmm :thinking:

Ahh yes maybe : on Mac …

from sys import exec_prefix gives:
file:///C:/Program Files/Rhino 6/Plug-ins/IronPython/IronPython.DLL
Is this different on a Mac?

Ahh I think I was looking for os.sep
Should be backslash for windows, forward for Mac …?

from sys import getwindowsversion

print getwindowsversion()
sys.getwindowsversion(major=10, minor=0, build=17134, platform=2, service_pack='')
Is this different on a Mac?

I don’t have a Mac with Rhino. Maybe @diff-arch could check a few of these … ahh already done by the JesterKing

os.sep gives
on my Windows system.

Gives ‘/’ on my iPhone

Ok, I’ll go with os.sep = \ for Windows and os.sep = / for Mac.

Now I need someone to fix the PixelLayout locations in my form on a Mac system.

This gives on the Mac

sys.getwindowsversion(major=18, minor=5, build=0, platform=4, service_pack='')

Which looks like it agrees with the kernel version (platform.uname() on Python2.7 in terminal gives ('Darwin', 'jesterMacPro.local', '18.5.0', 'Darwin Kernel Version 18.5.0: Mon Mar 11 20:40:32 PDT 2019; root:xnu-4903.251.3~3/RELEASE_X86_64', 'x86_64', 'i386'), see third element of tuple.

But I don’t think this is a good indicator - what if in the future there is a Windows 18?

The os.sep is probably currently the best workaround, it gives on the Mac indeed a forward slash (as it would on any *nix type system). A proper functioning platform module would be much better though.

1 Like


What do you think of using os.sep = \ vs / that Graham found? This would be really simple.


Already edited my previous answer with my thoughts on that.

Are you saying the the Eto module should just work on a Windows and Mac system even when using PixelLayout style?

Ehm, no. I meant os.sep usage to identify Mac from Windows.