B25: How to get the value of a FCurve for a given frame?

Hi, I’m converting a script from 2.49 to 2.5 and got stuck in one part. I can’t find a way to get the value from a fcurve for a given frame.

The original code:

ipo = Blender.Ipo.Get("myIpoCurve")
imIpo = ipo[Blender.Ipo.OB_SCALEZ]
imNum = imIpo[frame]

In 2.5x I can get the action, but the FCurves inside the action can’t be called by the name (e.g. the old OB_SCALEZ) nor give me a direct access to their values for a given name.

action = bpy.data.actions.get("myActionName") #and now what?

Any suggestions? The script use actions not assigned to any objects to store data. That’s why instead of reading the scale of my object in a given frame I want to read it from an action.


This should work:

action = bpy.data.actions.get("myActionName")
curve = fcurves[your_index]
result = curve.evaluate(frame)

Thanks a lot Alex3007, that solved most of the problem.

I wonder if there is a way to get the fcurve other than through its id. E.g. using ‘ScaleZ’ or as in 2.49 OB_SCALEZ

object.animation_data.action.fcurves …blah, blah

The fcurve has a data_path and array_index property. For z scale for instance you could loop through the fcurves collection and check for data_path = “scale” and array_index = 2 …

action = bpy.data.actions.get(“myActionName”)
curve = fcurves[your_index]
result = curve.evaluate(frame)

@ Alex3007, can you explain that? getting the action is no problem,
but which object is in the fcurve variable?

ah sorry.

i get it:

action = bpy.data.actions.get("CubeAction")
curve = action.fcurves[0]
result = curve.evaluate(111)

but i dont understand how to get the curve via name. can someone explain this deeper?

for fcurve in action.fcurves:
    if  fcurve.data_path == "location" and fcurve.array_index == 0:
        print("we have the x location fcurve")

nice, thanks!