for the addon I'm working on, I need a list of all fcurves (a list of all selected/visible fcurves would be enouph) Do I really have to loop through all animation_data objects to get this list?
Thanks in advance, Jacques Lucke
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.
Sign up to join this communityfor the addon I'm working on, I need a list of all fcurves (a list of all selected/visible fcurves would be enouph) Do I really have to loop through all animation_data objects to get this list?
Thanks in advance, Jacques Lucke
You can use bpy.data.actions
to get a list of all F-Curves in the scene, but actions are not associated with objects, scenes or nodes:
for i in bpy.data.actions:
print (i.name)
for fcu in i.fcurves:
print (fcu)
for keyframe in fcu.keyframe_points:
x, y = keyframe.co
print (x,y)
It's only possible to check if the actual object is associated with an action via animation_data in a reverse operation with Object.animation_data.action
to get something like: bpy.data.actions['Action']
. Another option is to check animation_data.action.name
.
If you need to know which F-Curve is applied to objects or nodes in your scene, the only way is to use animation_data and iterate through all components like:
Object.animation_data
- F-Curves of an ObjectScene.animation_data
- F-Curves of the SceneMaterial.animation_data
- F-Curves of a Materialimport bpy
import math
obj = bpy.context.active_object
keyframes = []
anim = obj.animation_data
if anim is not None and anim.action is not None:
for fcu in anim.action.fcurves:
print (fcu)
for keyframe in fcu.keyframe_points:
x, y = keyframe.co
print (x,y)
if x not in keyframes:
keyframes.append((math.ceil(x)))
To get the F-Curves of all objects in the scene you can use bpy.data.objects
and iterate through the objects in the scene like:
object_list = bpy.data.objects
for i in object_list:
anim = i.animation_data
if anim is not None and anim.action is not None:
for fcu in anim.action.fcurves:
print (fcu)
obj = bpy.context.object
shader = obj.data.materials[0].node_tree
anim_data = shader.animation_data
for fcu in anim_data.action.fcurves:
print (fcu)
for keyframe in fcu.keyframe_points:
x, y = keyframe.co
print (x,y)