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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.