📋 Metadata

  • Author: Pluglug
  • Date: 2023-03-11 20:24:35
  • Type: discussion

💬 Content

Lately I have been trying to master Property and one thing I have figured out that I would like to share.
When exchanging values with bpy.context, sometimes the value is a string.
In that case I thought I could just use Enum, but it only supports numbers.
After much research, I found a way to use a dictionary.
Here is an example of an Enum Property to switch between Cycles and Eevee.

# menu name: "Render Engine"

# Getter
return {'CYCLES': 0, 'BLENDER_EEVEE': 1}[C.scene.render.engine]
# Setter
C.scene.render.engine = ['CYCLES', 'BLENDER_EEVEE'][value]

# Usage (Custom tab)
L.row(align=False).prop(props(), "Render Engine", expand=True)

I am happy to find this way, but if you have a better way, please let me know. I can be happier.


I don’t know if this is a bug or a specification, but the Enable or Disable Menu Slot option in Enum does not seem to be working. However, I don’t seem to use it at the moment, so it’s not a problem.

Also, it would be nice to be able to use custom icons here as well. It is a way to improve visibility for the user.


🔗 View on Blender Artists