Scripted expression for driver

Hi,

I have a driver for the “X euler rotation” value of a posed armature bone. This is the (simplified) expression:

bpy.data.actions[‘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 bpy.data”. I did try to get rid of bpy.data 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 bpy.data.actions[‘HumanLeg’] or bpy.data.actions[‘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?
Thanks.

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

bpy.data.objects[‘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
pose.bones[“Leg.Upper.R”].rotation_euler[0]
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 https://www.blender.org/manual/animation/basics/drivers.html
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.

Attachments

simpledriver.blend (464 KB)