3
$\begingroup$

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
$\endgroup$
5
  • $\begingroup$ i think it's the same as normal driver just use 'scripted expression' $\endgroup$
    – Chebhou
    Mar 12, 2015 at 18:54
  • $\begingroup$ 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 $\endgroup$
    – ISaenz
    Mar 12, 2015 at 19:06
  • 1
    $\begingroup$ can you post this code line ? $\endgroup$
    – Chebhou
    Mar 12, 2015 at 19:22
  • $\begingroup$ @ISaenz Your only supposed to write a one line snippet - I think that's why you get an error $\endgroup$ Mar 12, 2015 at 19:56
  • $\begingroup$ Related: blender.stackexchange.com/a/48158/2843 $\endgroup$
    – Samoth
    Mar 25, 2016 at 20:06

1 Answer 1

8
$\begingroup$

your example can be implemented as in the following driver :

enter image description here

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

$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .