Change Current Frame acc. to Active Layer I need to write a script, that automatically changes the current frame according to the active layer. For example if layer 1 is active, current frame is 1. If layer 2 is active current frame is 11. There are 2 problems:

If I run this code:

 bpy.ops.anim.change_frame(frame=25)


it gives error:

Expected an timeline/animation area to be active


I can read the active layer via bpy.context.scene.active_layer however, I have no idea how to make this script always check the active layer.
You can do this using the below script:

import bpy

if bpy.context.scene.active_layer == 1:
    bpy.context.scene.frame_current=1
elif bpy.context.scene.active_layer == 2:
    bpy.context.scene.frame_current=11