Post #4644: Lately I have been trying to master Property and one thing I have figured out th

๐Ÿ“‹ Metadata

  • Author: Pluglug
  • Date: 2023-03-11 20:24:35
  • Type: discussion
  • Quality Score: 7/10

๐Ÿท๏ธ Tags

property-editor python-scripting intermediate unsolved

  • Property Editor
  • Python Scripting
  • Custom Icons

๐Ÿ’ฌ 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