38 lines
906 B
Python
38 lines
906 B
Python
from dataclasses import dataclass
|
|
from typing import Any
|
|
|
|
import bpy
|
|
|
|
|
|
|
|
@dataclass
|
|
class BlenderProperty:
|
|
"""
|
|
Blender Property abstraction, used since a Blender property value isn't
|
|
directly accessible from its Property object representation
|
|
NOTE: Do not rely on value being up-to-date, data will get stall
|
|
"""
|
|
rep: bpy.types.Property
|
|
attr: Any
|
|
|
|
|
|
def all_subclasses(cls):
|
|
return set(cls.__subclasses__()).union(
|
|
[s for c in cls.__subclasses__() for s in all_subclasses(c)]
|
|
)
|
|
|
|
|
|
def get_bl_default(prop: bpy.types.Property):
|
|
"""Get the default value of a Blender property"""
|
|
if getattr(prop, "is_array", False):
|
|
return list(prop.default_array)
|
|
elif hasattr(prop, "default"):
|
|
return prop.default
|
|
|
|
|
|
def set_bl_attribute(bl_object, attr, value):
|
|
try:
|
|
setattr(bl_object, attr, value)
|
|
except Exception as e:
|
|
print(e)
|