Im having so much trouble using the getter/setter for an EnumProperty. I have my property definition like:
blend_modes = (
("REGULAR", "Regular", "", 1),
("HARDLIGHT", "Hardlight", "", 2),
("ADD", "Add", "", 3),
("SUBTRACT", "Subtract", "", 4),
("MULTIPLY", "Multiply", "", 5),
("DIVIDE", "Divide", "", 6),
)
blend_mode : bpy.props.EnumProperty(items=blend_modes, name="Blend Mode",
description="TODO add description",
default="REGULAR", set=set_blend_mode, get=get_blend_mode)
And the get/set:
def get_blend_mode(self):
# return "REGULAR"
# return 1
# return self.get("blend_mode", "Regular")
return self.get("blend_mode", "REGULAR")
# return getattr(self, "blend_mode", "REGULAR")
# return getattr(self, "blend_mode", ("REGULAR", "Regular", "", 1))
# return getattr(self, "blend_mode", 1)
# return getattr(self, "blend_mode", {'REGULAR'})
# return getattr(self, "blend_mode", None)
# return getattr(self, "blend_mode", "")
# return int(getattr(self, "blend_mode", 1))
# if "blend_mode" in self:
# return self["blend_mode"]
# else:
# return 1
# return self.get("blend_mode", int("REGULAR"))
# return self.get("blend_mode", 1)
# return getattr(self, "blend_mode", list(self.blend_modes)[0])
def set_blend_mode(self,value):
print(f"{value = }")
print(f"{type(value) = }") # says its an int
value2 = "REGULAR"
if value == 1:
value2 = "REGULAR"
elif value == 2:
value2 = "HARDLIGHT"
elif value == 3:
value2 = "ADD"
elif value == 4:
value2 = "SUBTRACT"
elif value == 5:
value2 = "MULTIPLY"
elif value == 6:
value2 = "DIVIDE"
print(f"{value = } AFTER")
self["blend_mode"] = value
# self["blend_mode"] = str(value)
# self["blend_mode"] = int(value)
# self["blend_mode"] = value2
But I got an error:
in get_blend_mode
TypeError: 'str' object cannot be interpreted as an integer
The commented code are all the things that I've already tried.
The value
in the setter is always an int. Even though, via Blender's console, I can't set the blend_mode property of my object as an int (gives an error). But the setter gets an int. And despite I tried to convert that int to a str with the value on the enum, keeps complaining.
I wasn't able to see any example in the API or anywhere, so I'm pretty lost right now.