How to run script on every frame in Blender Render?

What are the options to run script in Blender Render on every frame? Preferably it would have to run both in preview and in Animation (Render active scene).

Lets say I want to print “Hello World” to console on every frame as an example.

Application handlers can be used for this:

import bpy

def run_script(scene):
    print("Hello World")

This will execute the ‘run_script’ method before the frame changes during timeline playback and during render. To run the method after the frame changes, replace ‘frame_change_pre’ with ‘frame_change_post’. If you want the method to only run while rendering and not during playback, use ‘render_pre’ and 'render_post’​.

1 Like

Thanks for reply.

What I fail to understand is how to call that script or make it be call when either animation or play buttons are pressed. Via Console, via Run script button in text editor?
Sorry if this is obvious, I have no experience with scripting outside Blender Game Engine.

Figured it out… Just run this once in text editor and it will run function where specified (frame_change_pre in stis case) from that.

Thank you!!