3
$\begingroup$

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

$\endgroup$
4
  • $\begingroup$ see this question it is almost the same $\endgroup$
    – Chebhou
    Commented Apr 6, 2015 at 17:36
  • $\begingroup$ so it's OK to close this as a duplicate ? $\endgroup$
    – Chebhou
    Commented Apr 6, 2015 at 17:41
  • 3
    $\begingroup$ @Chebhou Questions should be closed if the question is the same, not because one may have an answer which is the same. The questions are quite different imo. See: meta.blender.stackexchange.com/questions/549/… $\endgroup$ Commented Apr 6, 2015 at 20:35
  • $\begingroup$ @RayMairlot good point, ok i'm voting to reopen $\endgroup$
    – Chebhou
    Commented Apr 6, 2015 at 21:26

1 Answer 1

5
$\begingroup$

F-Curves via Actions

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 Object
  • Scene.animation_data - F-Curves of the Scene
  • Material.animation_data - F-Curves of a Material
  • ...

F-Curves of an Object

import 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)

F-Curves of a Node Shader

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)
$\endgroup$
2
  • 1
    $\begingroup$ Thanks, the important thing you forgot here is that not onlyobjects can have keyframes but also scenes, nodes... $\endgroup$ Commented Apr 7, 2015 at 8:19
  • $\begingroup$ @JacquesLucke thanks for clearification. Iteration should be the same - but I'll try to update the code as soon as I can. $\endgroup$
    – p2or
    Commented Apr 7, 2015 at 8:32

You must log in to answer this question.

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