driver_namespace in multi-file addon?

Hi All,

I am working on a multiple file AddOn in Blender 2.7.1. In my init.py I import one of the files and activate the register() def for that file. Inside that register () I have a line of code.


def register():
    bpy.app.driver_namespace["returnWheelRotationFromDistance"] = returnWheelRotationFromDistance

I have an existing car rig that uses this driver on the x rotation of a pose bone to make a car wheel turn. However, the driver breaks and can not recognize the name space I have defined. Yes, I Updated Dependencies to try to “refresh” the scripted expression but it still fails because it can not recognize returnWheelRotationFromDistance.

What is the trick to making name space available for drivers in any scene?

I thought once you registered the name space it was globally available to any object in any scene?

I am wondering if the _RestrictedData concept is coming into play here.

While I can issue a line of code that momentarily seems to work, when the rest of the AddOn tries to reference that name space it is blank.

Where in an AddOn initialization should I activate my name space code?
.
.
.
Confirmed, any name space you setup in a register() which is activated by an init.py gets ignored even though it temporarily works.

So I put the name space code in to the draw.

Eck, what a hack but it works.


    def draw(self, context):
        try:
            print(bpy.app.driver_namespace["returnWheelRotationFromDistance"])
        except:
            bpy.app.driver_namespace["returnWheelRotationFromDistance"] = returnWheelRotationFromDistance

It would be nice to know what the correct method is that we are supposed to use to code such things?

Hi Atom,

Did you happen to find any more info on this? Because I’m looking for similar behaviour in my addon, and I can confirm that the ‘1-time-extension-of-the-driver-namespace’-approach doesn’t seem to work, which is quite annoying. I have followed your advice, but I’ve put my code inside the poll() instead of the draw() method, because my panel isn’t necessarily drawn until some conditions are met. I’m using 2.73, btw.

And it gets even more annoying: if I start blender (no scene), I can confirm that my method has been added to the driver namespace. However, when I then open a file that contains objects that use the driver, I get an error about the driver expression being invalid. I have to press ‘update dependencies’ to get it to work. Surely I can’t be expected to do this manually for all objects that use this driver expression, everytime a new file is opened? There must be a way to do this automatically on opening a file, no?

Any thoughts, anyone?