Enum value to string?

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

wbronchart
Posts: 12
Joined: Mon Apr 08, 2013 2:39 pm
Location: United Kingdom

Enum value to string?

Postby wbronchart » Sun Apr 28, 2013 12:05 pm

How do I get the "human readable" version of the value of, for example, brush.sculpt_tool: http://www.blender.org/documentation/bl ... culpt_tool

The value I get is an int. The documentation says, "Enum in [‘BLOB’, ‘CLAY’, ‘CLA.....". Where do I get this list of options so I can look up the name?

CoDEmanX
Posts: 894
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Postby CoDEmanX » Sun Apr 28, 2013 4:37 pm

you can either get them from API docs,

or provoke an error in pyconsole so it tells you the enum members:

Code: Select all

>>> C.tool_settings.sculpt.brush.sculpt_tool = 'foobar'
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
TypeError: bpy_struct: item.attr = val: enum "" not found in ('BLOB', 'CLAY', 'CLAY_STRIPS', 'CREASE', 'DRAW', 'FILL', 'FLATTEN', 'GRAB', 'INFLATE', 'LAYER', 'MASK', 'NUDGE', 'PINCH', 'ROTATE', 'SCRAPE', 'SIMPLIFY', 'SMOOTH', 'SNAKE_HOOK', 'THUMB')


Or more proper, access the bl_rna structure:

Code: Select all

>>> for i in C.tool_settings.sculpt.brush.bl_rna.properties['sculpt_tool'].enum_items:
...     i.identifier, i.name, i.value
...
('BLOB', 'Blob', 17)
('CLAY', 'Clay', 8)
('CLAY_STRIPS', 'Clay Strips', 18)
('CREASE', 'Crease', 16)
('DRAW', 'Draw', 1)
('FILL', 'Fill', 9)
('FLATTEN', 'Flatten', 7)
('GRAB', 'Grab', 5)
('INFLATE', 'Inflate', 4)
('LAYER', 'Layer', 6)
('MASK', 'Mask', 19)
('NUDGE', 'Nudge', 11)
('PINCH', 'Pinch', 3)
('ROTATE', 'Rotate', 14)
('SCRAPE', 'Scrape', 10)
('SIMPLIFY', 'Simplify', 15)
('SMOOTH', 'Smooth', 2)
('SNAKE_HOOK', 'Snake Hook', 13)
('THUMB', 'Thumb', 12)
I'm sitting, waiting, wishing, building Blender in superstition...

wbronchart
Posts: 12
Joined: Mon Apr 08, 2013 2:39 pm
Location: United Kingdom

Postby wbronchart » Sun Apr 28, 2013 8:18 pm

that does it! Thanks


Return to “Python”

Who is online

Users browsing this forum: No registered users and 1 guest