0
$\begingroup$

Given action name, a data path and an array index, how can I find the F-Curve associated to that action?

$\endgroup$
0
$\begingroup$

You need to use the fcurves.find(data_path, array_index) function. For example, we want to retrieve the F-Curve for the location’s Z channel, for an action named ActionName.

# Configuration
action_name = 'ActionName'
data_path = 'location'
array_index = 2

action = bpy.data.actions.get(action_name)
if not action:
    print('Action {} not found.'.format(action_name))
else:
    # Retrieve the specific F-Curve
    fc = action.fcurves.find(data_path, array_index)
    if fc:
        for kfp in fc.keyframe_points:
            print(kfp.handle_left)
            print(kfp.handle_right)
            print(kfp.interpolation)
            print('Frame = {:04}; Value = {}'.format(kfp.co[0], kfp.co[1]))
$\endgroup$
  • 1
    $\begingroup$ Use bpy.data.actions.get(name) else it will throw a KeyError $\endgroup$ – batFINGER Apr 1 '19 at 8:26
  • $\begingroup$ @batFINGER, You mean that, if the key is not present, operator[] will throw a KeyError exception, while get() will return None? I updated my answer to reflect this. Thanks. $\endgroup$ – Dazotaro Apr 2 '19 at 23:17

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.