1
$\begingroup$

I have an addon with various modules and submodules. One of these submodules is specifically for handlers. When testing my addon, I noticed that whenever I installed and loaded the addon, the handler within my handler module would not register. How do I register a persistent handler as part of a submodule in an addon? And, how do I make sure that the handler is only registered once, and unregistered if the addon is removed?

import bpy
import os
from bpy.app.handlers import persistent

@persistent
def my_load_handler(dummy):
    print("Load Handler:", bpy.data.filepath)

def register():
    bpy.app.handlers.load_post.append(my_load_handler)

def unregister():
    bpy.app.handlers.load_post.remove(my_load_handler)
$\endgroup$
1
  • $\begingroup$ Why not call register() from the other module? $\endgroup$ – JakeD Apr 13 '17 at 11:22
2
$\begingroup$

Blender only calls register() and unregister() on the top-level module, i.e. the file that has the bl_info dict in it. You're responsible for calling things on your submodules.

You could be importing a module that handles registration on something wildly different. For example, a register() function in some submodule could register a new user here on Stack Overflow. Blender doesn't know which function does which, and thus only calls that one top-level register() function.

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.