1
$\begingroup$

Is there a way to add a property group to this method of registering, without adding a separate register/unregister function?

classes = (
    some_scene_variables
    some_operator,
)

register, unregister = bpy.utils.register_classes_factory(classes)

At the moment I am doing this, which works:

classes = (
    some_scene_variables,
    some_operator,
)

def register():
    for cls in classes:
        bpy.utils.register_class(cls)
    bpy.types.Scene.myvars = bpy.props.PointerProperty(type = some_scene_variables)

def unregister():
    for cls in classes:
        bpy.utils.unregister_class(cls)
    del bpy.types.Scene.myvars 

But it seems wrong to change how I am registering just because I want to add a property group.

Thanks

Edit: Something similar to this (just for illustration, I know this would in no way work):

classes = (
    some_scene_variables
    some_operator,
    bpy.types.Scene.myvars = bpy.props.PointerProperty(type = some_scene_variables),

)

register, unregister = bpy.utils.register_classes_factory(classes)
$\endgroup$
  • $\begingroup$ Can you clarify your question? Change from what to what? Inheriting from PropertyGroup should work with your code above: class some_scene_variables(bpy.types.PropertyGroup)... $\endgroup$ – squarespiral Jan 15 at 12:27
  • $\begingroup$ @squarespiral The first code block shows what is described in the Blender 2.80 manual. register and unregister are generated using the register_classes_factory method. But since they are auto-generated, how would you add the PointerProperty to the scene now? $\endgroup$ – aliasguru Jan 15 at 14:03
  • $\begingroup$ So you want to get rid of the lines starting with "bpy.types.Scene.myvars =" and "del bpy.types.Scene.myvars"? $\endgroup$ – squarespiral Jan 15 at 14:55
2
$\begingroup$

Check the source

As with a lot of blender, can check the code for bpy.utils.register_classes_factory

def register_classes_factory(classes):
    """
    Utility function to create register and unregister functions
    which simply registers and unregisters a sequence of classes.
    """
    def register():
        from bpy.utils import register_class
        for cls in classes:
            register_class(cls)

    def unregister():
        from bpy.utils import unregister_class
        for cls in reversed(classes):
            unregister_class(cls)

    return register, unregister

As you can see it does no more than register unregister classes. (Notice the reversing of list in unregister)

I would recommend using your own register methods. Even prior, would recommend own register methods over the now defunct bpy.utils.register_module()

To still use the factory, in conjunction with your own methods.

foo, bar = bpy.utils.register_classes_factory(classes)

def register():
    foo()
    # do other stuff

etc. Or write your own factory that also takes type, property pairs.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.