0
$\begingroup$

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.

$\endgroup$
1
$\begingroup$

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

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – batFINGER Jan 4 '18 at 14:37
  • $\begingroup$ Both things now fixed in the code above. Thanks. $\endgroup$ – tintwotin Jan 5 '18 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.