How to detect scene strips in the VSE on frame changes?

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.

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()


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

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