The documentation on
If the class has a register class method it will be called before registration.
How should this method be declared? What arguments will it be given?
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.Sign up to join this community
A class method takes at least one argument - the class itself. Here,
register (and its counterpart,
unregsiter) do not take anything else, so you must declare them this way:
@classmethod def register(cls): pass @classmethod def unregister(cls): pass
You have a good example of their usage in Cycles'
class CyclesRenderSettings(bpy.types.PropertyGroup): @classmethod def register(cls): bpy.types.Scene.cycles = PointerProperty( name="Cycles Render Settings", description="Cycles render settings", type=cls, ) cls.device = EnumProperty( name="Device", description="Device to use for rendering", items=enum_devices, default='CPU', ) # ... and so on adding properties to cls @classmethod def unregister(cls): del bpy.types.Scene.cycles
That way, you can embed the definition of your propertygroup and handle its container’s creation and deletion inside the class, instead of having to create/delete
bpy.types.Scene.cycles in the global (un)register funcs.