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
โ๏ธ Related PME Features
- 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.