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$

1 Answer 1

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$
2
  • $\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$ Jun 13, 2017 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, 2017 at 20:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .