# Running a script for each frame

If there is an object which has a property that which varies with each frame, would it be possible to to build a script that can access that property before each frame is rendered and thus change another property?

• It does seem to answer the question of running the script before rendering. But would it be done before each frame is rendered? Also I'm new to scripting. – user3927312 Mar 21 '15 at 21:04
• You could try using calling this function: bpy.app.handlers.frame_change_post with a function as a parameter. Check the API here: blender.org/api/blender_python_api_2_60_6/bpy.app.handlers.html – someonewithpc Mar 21 '15 at 21:11
• Could you provide your current script, so I can modify it to do what you want? – someonewithpc Mar 21 '15 at 21:15
• Sorry but I have no script. I'm thinking about creating an addon and I wanted some knowledge of how to do so. Thanks for the offer, I'd really like to collaborate with someone sometime in the future. – user3927312 Mar 21 '15 at 21:49

## 1 Answer

One way is by using drivers. Drivers allow you to calculate a value to use, this may be from other values in the same object, or from other objects. This answer provides examples. Also consider that drivers may be disabled by the user.

Another way is to setup a handler function. You could choose between using frame_change_post or a render_pre. You simply define your function and then append it to the handler list, then remove it when it is no longer needed.

def my_handler(scene):
val = scene.objects['Cube'].location.x
scene.objects['Sphere'].location.y = val + 1.6

def register():
bpy.app.handlers.frame_change_post.append(my_handler)

def unregister():
bpy.app.handlers.frame_change_post.remove(my_handler)