4

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?

satishgoda
  • 8,064
  • 2
  • 18
  • 35
xeruf
  • 393
  • 3
  • 14

1 Answers1

8

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()
dr. Sybren
  • 7,139
  • 1
  • 23
  • 52
  • 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... – xeruf Jul 12 '17 at 23:48
  • I've updated my answer to use a load_post handler. Haven't tried it myself, but it should work like this ;-) – dr. Sybren Jul 13 '17 at 20:22