As my Addon started growing, I decided to split the ui into different files. I have several subfolders with modules that I want to register und unregister in my main script. I tried to manage this with

from folder.subfolder import module1
from folder.subfolder import module2


def register():

def unregister():

Inside module1.py, it looks something like this:

import bpy

class MyPanel(bpy.types.Panel):
    bl_label = "MyPanel"
    bl_idname = "...."
    bl_space_type = "...."
    bl_region_type = "...."

    def draw(self, context):

However, it always prints out this error message:

        Traceback (most recent call last):
  File "C:\Program Files\Blender Foundation\Blender\2.79\scripts\modules\addon_u
tils.py", line 350, in enable
  File "C:/path/to/main/script.py", line 2388, in register
  File "C:\Program Files\Blender Foundation\Blender\2.79\scripts\modules\bpy\uti
ls\__init__.py", line 685, in register_module
    raise Exception("register_module(%r): defines no classes" % module)
Exception: register_module(<module 'module1' from 'C:/path/to/module1.py'>): defines no classes

What do I need to change in order to be able to register and unregister external modules properly?

  • $\begingroup$ Animation nodes, has a register() in each submodule, the addons main register() calls the register for each submodule. Look here $\endgroup$ – sambler May 23 '18 at 5:07
  • $\begingroup$ I see, but if you reload Animation Nodes by pressing F8, it prints the same error message (...defines no classes). I try to circumvent this behaviour $\endgroup$ – J. Doe May 23 '18 at 11:44
  • $\begingroup$ It is common to use importlib.reload see this example. I expect that for a complex setup as above you should be able to call unregister() and then register() for each submodule when bpy is already in locals. $\endgroup$ – sambler May 24 '18 at 0:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.