Batch registering multiple classes in blender 2.8

Hey again,

yesterday I wrote a new, cleaner version of this auto-load functionality.
I plan to use it in a template in my VS Code extension, however I need to do some more testing first. Maybe you want to test it as well.

You can download the file here: https://gist.github.com/JacquesLucke/11fecc6ea86ef36ea72f76ca547e795b

Just put it into your main addon directory.
Then in the __init__.py file do this:

from . import auto_load

auto_load.init()

def register():
    auto_load.register()

def unregister():
    auto_load.unregister()

This should automatically

  1. import all modules in your addon
  2. discover all classes, that need to be registered
  3. sort the classes in case there are dependencies between them (e.g. when you use bpy.props.CollectionProperty
  4. register all classes
  5. call a register function in all modules that have one (except in the main __init__.py and in auto_load.py)

Limitations:

  • Can’t register keymaps, handlers, … You have to do that manually in a register function in any module. Maybe I’ll provide utilities to register these things later as well.
  • You can’t have classes you want to register in the __init__.py file. However I think this is actually good.
5 Likes