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
- import all modules in your addon
- discover all classes, that need to be registered
- sort the classes in case there are dependencies between them (e.g. when you use
bpy.props.CollectionProperty - register all classes
- call a
registerfunction in all modules that have one (except in the main__init__.pyand inauto_load.py)
Limitations:
- Can’t register keymaps, handlers, … You have to do that manually in a
registerfunction 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__.pyfile. However I think this is actually good.