Scripted expression for driver


I have a driver for the “X euler rotation” value of a posed armature bone. This is the (simplified) expression:[‘HumanLeg’].fcurves[0].evaluate(42)

It works, but my problem is the warning that the “driver expression may not work correctly” and the tip to use “variables instead of”. I did try to get rid of by adding a variable, but nothing I use for the variable seems to be valid, i.e. the “Path” is shown in red. The only two options in this expression I have is replacing either[‘HumanLeg’] or[‘HumanLeg’].fcurves[0] by a variable. So the expression would be either var.fcurves[0].evaluate(42) or var.evaluate(42)

However, if I select the action and don’t enter anything in the Path textbox, it’s invalid. Entering fcurves[0] in the Path textbox is also invalid. So I don’t know what to enter. Any clue how to solve this?

I just see that it is valid to enter just fcurves as the data path. Consequently, I should be able to enter var[0].evaluate(42) as the scripted expression, but this is now considered an “Invalid Python expression”. What’s wrong now?
Thanks again.

Yes, of course, right after posting… ^^
I see in the console that

 TypeError: 'float' object is not subscriptable

Why is HumanLeg.fcurves a float object? (HumanLeg being an action)

Well, ok, I literally went the wrong path. I have to follow the object related pose, so the base is[‘HumanArmature’].pose.bones[‘Leg.Upper.R’]

which returns a PoseBone object. The only thing I need now is an evaluate() function like the FCurve type offers where I can pass the frame as an argument. I don’t find it. I’m I overlooking something (again)?

Didn’t intend to talk to myself. Sorry.
I am able to refer to
but obviously I am unable to pass a frame number. Consequently, it seems my goal is not reachable.

Hi Willi,

Looking at your OP it appears you need to check out
Here is a simple (silly) example of a driver set up … The x euler rotation of bone1 is driven by the sine of the frame times the y rotation of bone. (Transform channel) …

PS you will need to run the script in the scripts window for the driver to work.


simpledriver.blend (464 KB)