1
$\begingroup$

I would like to get the selected channel in python. But I Don't find the right function to do it. or maybe it's the way I select the channel with the mouse in the graph editor ?

I tried based on this post but that don't work. I don't know why. Maybe the API have changed since then ? I'm using blender 3.4.1

Do you know how to do it ? Thanks !

import bpy

# Get the selected fcurves
selected_fcurves = bpy.context.selected_editable_fcurves

# Check if any fcurve is selected
if selected_fcurves:
    # Print the name of each selected channel
    for fcurve in selected_fcurves:
        print("Selected Channel:", fcurve.data_path)
else:
    print("No fcurves selected.")

enter image description here

$\endgroup$

1 Answer 1

0
$\begingroup$

You are running your code in the text editor. But it should run in the graph editor. Therefore you have to override your context with this:

bpy.context.temp_override

More info here: https://docs.blender.org/api/current/bpy.types.Context.html#bpy.types.Context.temp_override

Make sure that your graph editor is open, an object is selected and that this object has selected fcurves, else the code won't work.

import bpy


area = [area for area in bpy.context.screen.areas if area.type == "GRAPH_EDITOR"][0]
print("area is", area)

with bpy.context.temp_override(area=area):
    # Get the selected fcurves
    selected_fcurves = bpy.context.selected_editable_fcurves

    # Check if any fcurve is selected
    if selected_fcurves:
        # Print the name of each selected channel
        for fcurve in selected_fcurves:
            print("Selected Channel:", fcurve.data_path)
    else:
        print("No fcurves selected.")
$\endgroup$
1
  • 1
    $\begingroup$ Thanks for the fast response ! It works. $\endgroup$
    – Charles K
    Commented May 14, 2023 at 10:53

You must log in to answer this question.

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