To correctly set values to an EnumProperty type we need to know all its possible entries.
If we try to set a value to an EnumProperty that is out of its available variants, Blender will throw an error:
TypeError: bpy_struct: item.attr = val: enum “xxx” not found in (‘value_001′, value_002’, …)
where:
xxx – the value we tried to set to an EnumProperty
value_001, value_002, … – possible EnumProperty values
The list of available EnumProperty values can be obtained through its rna-structure.
Let’s define a function that will return a list of possible EnumProperty values, with the object and enumerated property name obtained in its input parameters:
1 2 3 4 |
import bpy def show_enum_values(obj, prop_name): print([item.identifier for item in obj.bl_rna.properties[prop_name].enum_items]) |
For example, let’s get all possible coordinate systems of the scene:
1 2 3 |
show_enum_values(bpy.context.scene.transform_orientation_slots[0], 'type') # ['GLOBAL', 'LOCAL', 'NORMAL', 'GIMBAL', 'VIEW', 'CURSOR'] |
or all possible mesh modes:
1 2 3 |
show_enum_values(bpy.context.object, 'mode') # ['OBJECT', 'EDIT', 'POSE', 'SCULPT', 'VERTEX_PAINT', 'WEIGHT_PAINT', 'TEXTURE_PAINT', 'PARTICLE_EDIT', 'EDIT_GPENCIL', 'SCULPT_GPENCIL', 'PAINT_GPENCIL', 'WEIGHT_GPENCIL'] |