# How to create a PyDriver in blender 2.7

I've heard of PyDrivers where you can put python code into a driver, & I'm wondering, how would you do that in blender 2.7x without resorting to a lower blender version?

Here's what I'd like to put in the driver:

(ob(‘Armature’).getPose().bones[‘Bone.001’].head - ob(‘Armature’).getPose().bones[‘Bone’].head).length/250

• i think it's the same as normal driver just use 'scripted expression' – Chebhou Mar 12 '15 at 18:54
• I've tried putting in a short python script in the expression field when using 'scripted expression' but then I get an 'Invalid Python Expression' error – ISaenz Mar 12 '15 at 19:06
• can you post this code line ? – Chebhou Mar 12 '15 at 19:22
• @ISaenz Your only supposed to write a one line snippet - I think that's why you get an error – someonewithpc Mar 12 '15 at 19:56
• – Samoth Mar 25 '16 at 20:06

your example can be implemented as in the following driver :

but for more complex drivers refer to this DOC page , the important part is that you can define your function and add it to driver namespace as in this example :

import bpy

def driverFunc(val):

return val * val    # return val squared

bpy.app.driver_namespace['driverFunc'] = driverFunc    # add function to driver_namespace


now you can use it the driver scripted expression