0
$\begingroup$

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

$\endgroup$
1

1 Answer 1

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$
2
  • 1
    $\begingroup$ Use bpy.data.actions.get(name) else it will throw a KeyError $\endgroup$
    – batFINGER
    Commented Apr 1, 2019 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
    Commented Apr 2, 2019 at 23:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .