You can use set_blend_mode()
with value
as str
e.g. bpy.context.scene.custom.set_blend_mode('HARDLIGHT')
import bpy
from bpy.types import Panel, PropertyGroup
from bpy.props import *
class CUSTOM_PG_property_group(PropertyGroup):
def get_blend_mode(self):
return self.get("blend_mode", "REGULAR")
def set_blend_mode(self, value):
if value == 'REGULAR':
value = 0
elif value == 'HARDLIGHT':
value = 1
elif value == 'ADD':
value = 2
elif value == 'SUBTRACT':
value = 3
elif value == 'MULTIPLY':
value = 4
elif value == 'DIVIDE':
value = 5
self["blend_mode"] = value
blend_mode : EnumProperty(
name = "Blend Mode",
description = "TODO add description",
items = (
("REGULAR", "Regular", ""),
("HARDLIGHT", "Hardlight", ""),
("ADD", "Add", ""),
("SUBTRACT", "Subtract", ""),
("MULTIPLY", "Multiply", ""),
("DIVIDE", "Divide", ""),
),
get = get_blend_mode,
set = set_blend_mode,
default = "REGULAR",
)
class HelloWorldPanel(Panel):
bl_label = "Hello World Panel"
bl_idname = "OBJECT_PT_hello"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "Test"
def draw(self, context):
layout = self.layout
custom = context.scene.custom
layout.prop(custom, 'blend_mode')
classes = (
CUSTOM_PG_property_group,
HelloWorldPanel,
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Scene.custom = PointerProperty(type=CUSTOM_PG_property_group)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
del bpy.types.Scene.custom
if __name__ == "__main__":
register()