0

How do I detect with Python a strip in VSE being selected with the mouse?

I want to use the strips in the sequencer as buttons to select cameras in the 3D View. So I just want to detect the moment a strip is clicked.

tintwotin
  • 2,296
  • 10
  • 24

1 Answers1

1

This script will print to console the name of the new strip being selected in the sequencer:

import bpy 

oldStrip = bpy.context.scene.sequence_editor.active_strip

def sequencer_update(scene):
    global oldStrip
    activeStrip = scene.sequence_editor.active_strip
    if activeStrip:                                     
        if oldStrip.name != activeStrip.name:
            print("New strip selected: "+activeStrip.name) 
            oldStrip = activeStrip              

def register():

    handlers = bpy.app.handlers.scene_update_pre
    for handler in handlers:
        if ("sequencer_update" in str(handler)):
            handlers.remove(handler)
    handlers.append(sequencer_update)

def unregister():
    handlers = bpy.app.handlers.scene_update_pre
    for handler in handlers:
        if ("sequencer_update" in str(handler)):
            handlers.remove(handler)

    bpy.utils.unregister_module(__name__)

if __name__ == "__main__":
    register()

#unregister()

Related: how-to-detect-updates-in-sequencer-by-comparing-to-a-global-variable

tintwotin
  • 2,296
  • 10
  • 24
  • 1
    What happens if you delete the active strip while this handler is running? And as i commented previously, the scene is the argument of a scene update handler, not the context. .. eg def handler(scene): and in the handler, strip = scene.sequence_editor.active_strip. – batFINGER Jan 04 '18 at 14:37
  • Both things now fixed in the code above. Thanks. – tintwotin Jan 05 '18 at 16:01