1
$\begingroup$

I'm trying to register multiple classes at the same time like this: I got it working like this

def register():
    bpy.utils.register_class(VIEW3D_PIE_SPECIALS)
    bpy.utils.register_class(SMART_BOOLEAN_ADD)
    bpy.utils.register_class(SMART_BOOLEAN_SUBTRACT)
    bpy.utils.register_class(SMART_BOOLEAN_SLICE)

But I want it to automatically register all classes in my file

Here is my attempt which isn't working yet:

classes = ('VIEW3D_PIE_SPECIALS','SMART_BOOLEAN_ADD','SMART_BOOLEAN_SUBTRACT','SMART_BOOLEAN_SLICE')


def register():
    for cls in classes:
        return 'bpy.utils.register_class('+(cls)+')'

def unregister():
    for cls in classes:
        return 'bpy.utils.unregister_class('+(cls)+')'
$\endgroup$
2
$\begingroup$

You're looking for register_module:

def register():
    bpy.utils.register_module(__name__)

def unregister():
    bpy.utils.unregister_module(__name__)

It grabs all the relevant classes in the file.

$\endgroup$
  • $\begingroup$ Thanks this works perfectly. One case I'm having trouble with though is registering multiple keymaps. I have them all in one class, but they are not registering using this method (works if I register the class manually). Any ideas? $\endgroup$ – Vaughan Ling Jun 13 '17 at 16:55
  • $\begingroup$ As far as I know you'd have to register keymaps separately through register_keymaps(), but that's a bit outside my experience. Perhaps this will be helpful: blender.stackexchange.com/questions/40755/… $\endgroup$ – Kiki W. Jun 14 '17 at 20:54

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.