Given action name, a data path and an array index, how can I find the F-Curve associated to that action?
1 Answer
$\begingroup$
$\endgroup$
2
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]))
-
1$\begingroup$ Use
bpy.data.actions.get(name)
else it will throw aKeyError
$\endgroup$ Commented Apr 1, 2019 at 8:26 -
$\begingroup$ @batFINGER, You mean that, if the key is not present, operator[] will throw a
KeyError
exception, whileget()
will returnNone
? I updated my answer to reflect this. Thanks. $\endgroup$– DazotaroCommented Apr 2, 2019 at 23:17