The driver namespace
Can add functions and properties to the driver namespace
import bpy
def func(a, b, c):
return a * b * c
m = 9.4443299912
bpy.app.driver_namespace["f"] = func
bpy.app.driver_namespace["m"] = m
Then in a driver can use an expression like f(m, m, m)
Which can be typed directly into a field by preceding with a hash #
character.
There are a number of functions and properties etc already defined to the namespace, a sample of python console output.
>>> for k, v in bpy.app.driver_namespace.items():
... k, v
...
('asin', <built-in function asin>)
('asinh', <built-in function asinh>)
('atan', <built-in function atan>)
...
('pi', 3.141592653589793)
('e', 2.718281828459045)
...
EDIT: would like to see a "sub expression" driver variable type where you could do this for scalars, or using other defined variables. Fitting everything into the scripted expression can be a PITA.