0
$\begingroup$

I want to make it VERY obvious when auto keying is turned on in Blender. I want to write an add-on where, if auto keying is turned on, Blender's theme turns to Blender Light. Otherwise, Blender's theme is Blender Dark.

The core of the add-on is basically this:

if bpy.context.scene.tool_settings.use_keyframe_insert_auto == True:
    bpy.ops.script.execute_preset(menu_idname="USERPREF_MT_interface_theme_presets", filepath="C:\\Programs\\blender\\2.81\\scripts\\presets\\interface_theme\\blender_light.xml")
else:
    bpy.ops.script.execute_preset(menu_idname="USERPREF_MT_interface_theme_presets", filepath="C:\\Programs\\blender\\2.81\\scripts\\presets\\interface_theme\\blender_dark.xml")

Is it possible -- via an add-on -- to intercept when use_keyframe_insert_auto changes and then have this code execute? If so, how?

If that's not possible, what is the recommended way of handling this?

$\endgroup$
1

1 Answer 1

1
$\begingroup$

You can use a message bus subscription to do that.

The following script will call a function when 'use_keyframe_insert_auto' is changing from the UI.

The principle is:

  • Obtain a subscription link using path_resolve on the scene
  • Then use this link to subscribe in order to fire a function when the value changes

Here is the code (look at the console to see the printed results):

import bpy

#The callback when use_keyframe_insert_auto changed
def a_callback(scene):
    print( scene, "use_keyframe_insert_auto changed" )

def subscribe_to_scene(scene):

    #Get a rna subscription link from the scene
    subscribe_to = scene.path_resolve("tool_settings.use_keyframe_insert_auto", False)

    #Effectively subscribe to the rna path from the scene
    bpy.msgbus.subscribe_rna(
        key=subscribe_to,
        owner=scene,
        args=(scene,),
        notify=a_callback,
    )

subscribe_to_scene(bpy.context.scene)
$\endgroup$
0

You must log in to answer this question.

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