Blenderheads of Blender Stack Exchange. I have an add-on that I’ve been working on, and while it is 99% complete, the last 1% has me completely stumped.

The add-on is designed to set up the best settings in one button press, instead of the 10+ mouse clicks needed to set everything up manually. We’re talking about things such as setting UI Line Width to Thick, Python Tooltips to True, Autosave Time to 1 Minute, Load UI to False, Autokey to True, Unselected F-Curve Opacity to the minimum, and as of Blender 3.6, Only Selected Curve Keyframes to True, and much more, which would otherwise take a lot of navigating around Blender, and clicking on things. My dilemma in regards to the troublesome 1% of my addon is the various boolean toggles around Blender. In my case, the ones in the View menu for the Graph Editor specifically.

I am trying to have the Only Selected Curve Handles, and Show Cursor toggles set to True, and False respectively in the Graph Editor, but from the context of the 3D Viewport, so that way once you click the button and then go into the Graph Editor, everything will already be set up for you to have the best animation experience, since you won’t have to deal with seeing every curve keyframe all the once.

The thing with me and my add-ons is that even though we’re now at a point where there’s Blender 4.0 and above, and the Only Selected Curve Keyframes toggle got a much needed update with being placed in Edit > Preferences > Animation, which I still say is the best update in Blender 3.6, I do all of my add-on work in as low of a Blender version as possible, so that people using lower versions such as below 3.5 can still use as much as that particular Blender version allows.

I am aware that I can just assign the toggles to hotkey, but I want to be able to just set them up automatically with my add-on so that I, and others can just activate the add-on, press the button in the N panel, and not have to worry about remembering to press the hoteys, as shown in the image mock-up below.

How the toggles are currently set in the Graph Editor

Set up the best settings for Blender with one click

Graph Editor toggles after pressing Optimal Preferences button

Moving onto what I have tried, I first started with trying the obvious of copy pasting the code from the info window into the def execute section of my addon:

def execute (self, context):

bpy.context.space_data.use_only_selected_curves_handles = True
bpy.context.space_data.show_cursor = False

    return {“FINISHED”}

When I run the script, and then press the button for my operator, however, I get the following error:

Attribute Error: ‘SpaceView3D’ object has no attribute ‘use_only_selected_curves_handles’

Someone on the bpy discord server tried helping me out with the following code: def execute (self, context): for area in context.screen.areas: if area.type == 'GRAPH_EDITOR': editor_space = area.spaces [0] if editor_space == "VIEW_3D": editor_space_use_only_selected_curves_handles = True

And although it doesn’t produce an attribute error like what I was doing, the code block doesn’t activate the toggle when I run my operator, meaning that isn’t a working solution either…

I have also tried the following:

area = [area for area in bpy.context.screen.areas if area.type == ‘GRAPH_EDITOR’]

with bpy.context.temp_override (area = ‘VIEW_3D’):
bpy.context.space.data.use_only_selected_curves_handles = True

However, this gives me the following error:

SystemError: <built-in method temp_override of Context object returned a result with an exception set.

enter image description here

Lastly, I have tried Crantisz's answer to a similar question: Override space data display mode (Override space data display mode) my code for it looks like this:

def graph_editor_settings (context): graph_eidtor_list = [] for item in context.selected_ids: bpy.context.space.data.use_only_selected_curves_handles = True

def execute (self, context):
    for area in bpy.screen.areas:
        if area.type == 'GRAPH_EDITOR':
            override = bpy.context.copy()
            override [GRAPH_EDITOR] = area
            graph_editor_settings (override)

After trying everything I can think of to get the toggles to work, I am at a complete loss. I'd like to call upon the knowledgeable Blenderheads of Blender Stack Exchange.... please, I need help to finish the final 1% of my addon so I can say it's truly done, and put it out of my mind for good.


I just want to reiterate that the boolean switches in the View menu are NOT bpy.ops, but are actually bpy.context.space_data, which means I might need a different approach than some the questions or solutions I am seeing from similar situations.


1 Answer 1


You only need context overrides if you're going to override an operator. Here you're directly modifying data so you don't need to override the context.

The python tooltip is misleading but you can work your way up the documentation to find where you can tweak these properties.

Search for the property name in the docs

Find where it is defined

Find which type it is a subtype of (Go to the bottom of the screen or read the class name in the parentheses next to SpaceGraphEditor)

Find where Space is used

Find where Area is used

Find where Screen is used

And then simply

import bpy

graph_editor = next(a for a in bpy.context.screen.areas if a.type == "GRAPH_EDITOR")
space = graph_editor.spaces.active
space.use_only_selected_keyframe_handles = True
space.show_cursor = False
  • $\begingroup$ You're a hero among heroes, Gorgious. It worked. I've added your name to the author field of my Optimal Preferences. add-on. $\endgroup$
    – Sonario648
    Commented Dec 19, 2023 at 18:57
  • $\begingroup$ Hehe that's a lot of honor for such a simple addition, but thank you very much, cheers :) $\endgroup$
    – Gorgious
    Commented Dec 20, 2023 at 7:08

You must log in to answer this question.

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