How should I get the data of the axis selected in the curve editor?

When my mouse activates a certain axis, how should I get the data of the activated curve?

Because I want to write a script, when I click on this axis, other axes are automatically hidden, only this axis is displayed.

I tried to locate this bone to find his api, but failed……

Fcurves are stored in containers called actions.

When ran from a dopesheet editor, actions are linked to the space data:

context.space_data.action.fcurves

However the graph editor is not a dopesheet editor, so we need to go via context.object:

context.object.animation_data.action.fcurves

To get selected channels in the sidebar is same as getting the selected fcurves:

fcurves = context.object.animation_data.action.fcurves
fc = [f for f in fcurves if f.select]
1 Like

Thank you, your approach is right. In addition, there is another question I want to ask, when I select an axis, how can I automatically hide the other axis and show only the selected axis? Now what I can do is to click “Run Script” every time to get similar results.

This could get you started. Example macro which isolates selected channel.
Run script and use ctrl + left click on channel.

import bpy

class GRAPH_OT_focus_channel(bpy.types.Macro):
    bl_idname = "graph.focus_channel"
    bl_label = "Focus Channel"

if __name__ == "__main__":
    bpy.utils.register_class(GRAPH_OT_focus_channel)
    m = GRAPH_OT_focus_channel
    m.define("GRAPH_OT_reveal")
    m.define("ANIM_OT_channels_click")
    m.define("GRAPH_OT_hide").properties.unselected = True

    kc = bpy.context.window_manager.keyconfigs.addon
    km = kc.keymaps.get("Graph Editor Generic")
    if not km:
        km = kc.keymaps.new(
            "Graph Editor Generic", space_type="GRAPH_EDITOR", region_type="WINDOW")

    kmi = km.keymap_items.get("graph.focus_channel")
    if not kmi:
        kmi = km.keymap_items.new("graph.focus_channel", "LEFTMOUSE", "PRESS", ctrl=True)

1 Like

Thank you very much, you solved my big problem