1
$\begingroup$

In my addon everything is working fine.... other than

bpy.app.driver_namespace["Driver"] = driver

It works if I enable the addon on starting blender, but once I save user preferences, then it seems to not run that line of code but everything else works fine, as far as I can tell

I have tried putting it in classes and in the register function but nothing works

$\endgroup$

1 Answer 1

4
$\begingroup$

Use a persistent load_post handler to register your drivers to the driver namespace.

import bpy
from bpy.app.handlers import persistent
from bpy.app import driver_namespace as dns

def driver(x):
    return x

@persistent
def load_handler(dummy):
    print("Load Handler:", bpy.data.filepath)
    #dns = bpy.app.driver_namespace
    # register your drivers
    dns["xdriver"] = driver

def register():
    load_handler(None)
    bpy.app.handlers.load_post.append(load_handler)

def unregister():
    bpy.app.handlers.load_post.remove(load_handler)

if __name__ == "__main__":
    register()
$\endgroup$

You must log in to answer this question.

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