Import enum in GhPython

Hello guys,

I was wandering if it’s possible to import enum in GhPython. I know there is not module enum except the System.Enum but this doesn’t seem to work the same way.

I would like to do something simple for now if there is a way:

example from Python

from enum import Enum

class Color(Enum):
… RED = 1
… GREEN = 2
… BLUE = 3

Color.RED
Color.GREEN
Color.BLUE

I was searching the possibility also to import clr and import it from a .dll but I didn’t find anything to download for IronPython

If someone can help me figure this out I would really appreciate it.
Thanks a lot!!

Hi,

I don’t know about System.Enum, but you could for instance use a custom Python class:

class Color:
    def __init__(self, r, g, b):
        self.red = r
        self.green = g
        self.blue = b

    def __repr__(self):
        return "({}, {}, {})".fomat(self.red, self.green, self.blue)


if __name__ == "__main__":
    c = Color(255, 0, 0)
    print c

Or even something simpler like a dictionary:

if __name__ == "__main__":
    color = dict()
    color["red"] = 255
    color["green"] = 0
    color["blue"] = 0
    print color

Thank you for your quick reply. I already did something custom.
I just wanted to find a way to use Enum inside my library so it works for all my classes.

The point is when I call something outside of my class for example Colour. I want to see all the variables/ options that I have defined in this Enum class.

Hello,

There is a backport of enum on pypi but I cannot find the source code. I also found this one on GitHub but haven’t tried it / can’t vouch for it :