I have a simple EnumProperty with let's say two buttons. Now i want to create a primitive with one of the buttons. But a click at the button does nothing. There is a bit missing. The operator needs to be executed. And i cannot find a code example how to do so.
How do i execute an operator from an EnumProperty? How do i give those buttons a functionality now?
import bpy
class LayoutDemoPanel(bpy.types.Panel):
bl_label = "Test"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
def draw(self, context):
layout = self.layout
layout.label(text="Enum prop")
scene = context.scene
layout.prop(scene, "my_enum", expand=True)
def register():
bpy.utils.register_class(LayoutDemoPanel)
bpy.types.Scene.my_enum = bpy.props.EnumProperty(
name = "My enum",
description = "My enum description",
items = [
("mesh.primitive_cube_add", "Cube", "Create a cube"),
("mesh.primitive_shpere_add", "Sphere", "Create a Sphere"),
]
)
def unregister():
bpy.utils.unregister_class(LayoutDemoPanel)
bpy.types.Scene.my_enum
if __name__ == "__main__":
register()