Hey, quick question on learning “the Blender way” of doing things.
I’m creating an operator which uses an
EnumProperty called “action” to change its behavior. To improve usability, I wanted to implement the operator’s
description function. It should take the value of “action” and use its description as the operator’s tooltip.
Here’s what I came up with (irrelevant parts omitted):
class OBJECT_OT_test(Operator): action: EnumProperty(items=( ('ADD', "Add", "Adds a new item"), ('REMOVE', "Remove", "Removes an item"), ('GOTO', "Go to", "Go to an item") )) @classmethod def description(cls, context, properties): for action in cls.__annotations__["action"]["items"]: if action == properties.action: return action return None
But my solution feels incredibly hacky and could easily break (I don’t even know why the
 is needed, honestly). While it does work like expected, does anyone know of a nicer solution?
Of course I’d like a solution that doesn’t require you to duplicate the enum descriptions into another dictionary or the like.
So in my example: what’s a nicer way to convert a string like
'ADD' to its description
"Adds a new item"?
Thanks a lot in advance!