1
$\begingroup$

I need to detect scene strips in the VSE on the current frame, meaning on what strip is the play head at this moment? However I can't seem to find the right type(?) to attach the ".strip_elem_from_frame" function to, in order to get the info/name/type on the strip. Here's a test script which must run in a screen with a sequencer with scene and movie strips in it:

import bpy

#update at frame change
def currentStrip(*pArgs):
    print("Current Strip: "+str(bpy.context.sequences[0].strip_elem_from_frame(bpy.context.scene.frame_current))) #Doesn't detect any strips at all.

#add frame change handle
def attachAsHandler():
    for f in bpy.app.handlers.frame_change_pre:
        bpy.app.handlers.frame_change_pre.remove(f)
    bpy.app.handlers.frame_change_pre.append(currentStrip)

currentStrip()
attachAsHandler()    
$\endgroup$

1 Answer 1

0
$\begingroup$

This works, but I guess it could be more elegant and faster if ".strip_elem_from_frame" would work with scene-strips and nonactive strips. The current strip will be written in the Console.

import bpy

#update at frame change
def syncSceneLength(*pArgs):
    scn = bpy.context.scene
    seq = scn.sequence_editor
    cf = scn.frame_current
    for i in seq.sequences:    
        try:
            if (i.frame_final_start <= cf
            and i.frame_final_end > cf
            and not i.mute): 
                print("Current Strip: "+i.name)
        except AttributeError:
                pass

def attachAsHandler():
    for f in bpy.app.handlers.frame_change_pre:
        bpy.app.handlers.frame_change_pre.remove(f)
    bpy.app.handlers.frame_change_pre.append(syncSceneLength)

def detachAsHandler():
    bpy.app.handlers.frame_change_pre.clear()    

syncSceneLength()
attachAsHandler()
#detachAsHandler() #Uncomment this to stop handler
$\endgroup$
3
  • $\begingroup$ what should the for f in bpy.app.handlers.frame_change_pre: part do? if i understand it correct: go through all registered functions and remove theme. so this is the same as bpy.app.handlers.frame_change_pre.clear()?! both can remove functions added by other scripts / addons! be careful! but i think there is currently no way to remove the old function only when you rerun the script (as the script gets rerun you don't have access to the old function reference..) $\endgroup$ Commented May 11, 2019 at 14:53
  • $\begingroup$ Is it possible to then select the strips where the playhead is? i can't seem to figure it out $\endgroup$ Commented Dec 8, 2020 at 2:38
  • $\begingroup$ I don't know why someone posted this as a duplicate of your question. Imo, this question here is unrelated. But look at my answer at your original question and you'll find a working add-on which includes the feature you're after. $\endgroup$
    – tintwotin
    Commented Dec 8, 2020 at 8:03

You must log in to answer this question.

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