1

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)+')'

1 Answers1

2

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.

Kiki W.
  • 606
  • 4
  • 6
  • 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? – Vaughan Ling Jun 13 '17 at 16:55
  • 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: https://blender.stackexchange.com/questions/40755/how-to-register-keymaps-for-all-editor-types – Kiki W. Jun 14 '17 at 20:54