# Access only filtered/visible F-curves through python in graph editor

I'm looking for a way to be sure a script affect only f-curves that are showing up to the user in the graph editor (post filtering) for WYSIWYG style control.

In details: Currently I'm getting the actions from the objects directly after checking the properties of the graph editor (check if "show_only_selected" is on for exemple) in the graph editor, then try to get related actions from selected objects.

Problem is : With the filter show_only_selected toggled On in graph editor, In the case of armature selected, if some of it's bones are unselected there are hided in editor but still affected by the script (I get all the fcurves of the actions). Other animated properties might be affected while being invisible to the user or on the contrary being not affected while being visible.

A way to directly iterate on filtered f-curves would be really nice (if not necessary) to apply some script on what the user see/isolate.

Even more details in this blender artist thread :

• Please expand your question here too, rather than having link to BA. Wont take long with cut n paste. – batFINGER Oct 10 '17 at 10:06
• Done. Now does the legendary batFINGER has any solution for this ? ;) – Pullup Oct 10 '17 at 13:32

context.selected_editable_fcurves

New to blender 2.79.1 is context.selected_editable_fcurves Test script. Prepends a toggle button to graph editor header. Runs update code on each toggle that will print the visible fcurves to console.

Edited to include all "visible" fcurves in the graph editor.

import bpy
from bpy.props import BoolProperty

def foo(self, context):
selected = context.selected_editable_fcurves[:]
bpy.ops.graph.select_all_toggle(invert=True)
others = context.selected_editable_fcurves[:]
others.extend(selected)
others = set(others)
print("-" * 72)
print("%d selected of %d visible" % (len(selected), len(others)))
for fc in others:
fc.select = fc in selected
print("action:", fc.id_data.name,
"data_path:", fc.data_path,
"{%d}" % fc.array_index,
fc.select)

return None

bpy.types.Scene.testfc = BoolProperty(update=foo)

def testfc(self, context):
scene = context.scene
self.layout.prop(scene, "testfc", toggle=True)


Even before this context attribute became available, the same thing could be done by deselecting all fcurves (using a.fcurves.foreach_set("select", [False] * len(a.fcurves))) in all actions, then selecting all with bpy.ops.graph.select_all_toggle, those selected will be the visible ones, and reinstating to original selection.
• This is not exactly what I was looking for (since I want to get all the visible Fcurve, not selected only) But it's really interesting and might be super usefull ! When I use your script I get the Error : AttributeError: 'Context' object has no attribute 'selected_editable_fcurves'. in what context you suppose to get this ? I tried to find it manually in interactive console (with lines like bpy.context.window_manager.windows[0].screen.areas[8].spaces ...) but I could not found anything. – Pullup Oct 13 '17 at 14:46
• It looks like bpy.ops.graph.select_all_toggle(invert=True) has been replaced with bpy.ops.graph.select_all(action='INVERT') in 2.80! Also, if using filters in the graph editor results in NO visible fcurves, calling the select_all operator throws an incorrect context error! Any ideas on how to get around that? Thanks :) – andyV Dec 15 '18 at 3:56