4
$\begingroup$

I have a method x which I can add to the driver namespace like this:

bpy.app.driver_namespace["x"] = x

but the namespace is reset everytime I restart Blender, which then messes up my drivers. Is there a way to permanently add it to the namespace or auto-execute this script when starting Blender?

$\endgroup$

1 Answer 1

8
$\begingroup$

Put this code into a Python file and place it into ~/.config/blender/2.78/scrips/startup/my_driver_stuff.py (replace ~/config/blender with %APPDATA%/Blender Foundation/Blender on Windows, and something along those lines on MacOS).

import bpy

@bpy.app.handlers.persistent
def setup_driver(*args):
    bpy.app.driver_namespace["x"] = x
bpy.app.handlers.load_post.append(setup_driver)
setup_driver()
$\endgroup$
2
  • $\begingroup$ ok now that's weird... It created a "pycache" folder in the startup folder, presumably containing the compiled script. But the method is still not in the namespace... $\endgroup$
    – xeruf
    Commented Jul 12, 2017 at 23:48
  • $\begingroup$ I've updated my answer to use a load_post handler. Haven't tried it myself, but it should work like this ;-) $\endgroup$
    – dr. Sybren
    Commented Jul 13, 2017 at 20:22

You must log in to answer this question.

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