I need to write a custom driver function (because the algorithm I need is too complex to put into a single line). So, I thought I'd try making a custom driver...
I opened the file editor, pasted my function:
import bpy
def spinnerSlowdown(frame, cutoff, slowdownframes, offset):
r = radians(frame * -18) + offset
if frame < cutoff:
return r
elif frame < cutoff + slowdownframes:
factor = ((frame - cutoff) / slowdownframes)
factor = 1 - (factor - 1) * (factor - 1)
newFrame = cutoff + (slowdownframes * factor)
ret = radians(newFrame * -18) + offset
return ret
else:
newFrame = cutoff + slowdownframes
return radians(newFrame * -18) + offset
bpy.app.driver_namespace['spinnerSlowdown'] = spinnerSlowdown
... saved it, then ran the script (both with the arrow and Text / Run Script). No errors. (If I type some garbage into the script and run, I get an error, so I know it's at least compiling).
But, when I try to call that fn from a driver: spinnerSlowdown(#frame, 200, 100, radians(130))
It gives me the "Error: Invalid Python expression" message.
If I try to call it from the Python console:
>>> spinnerSlowdown(1,2,3,4)
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
NameError: name 'spinnerSlowdown' is not defined
So, it looks like my fn isn't visible.
Any ideas?
I'm a complete noob to writing Python inside Blender... so be kind.