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$
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$
  • $\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$ – Stefan Krüger May 11 at 14:53

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.