When I run the following script, current_frame is set AFTER the render.opengl():

bpy.context.area.type = 'VIEW_3D'
bpy.context.scene.frame_current = 234
bpy.data.scenes['Scene'].frame_current = 234

If I run the script again, the correct frame is rendered. How can I force the frame_current to be applied before the render?

(A solution without using an operator is also welcome, as I understand that ops are more for user interaction that for scripts and are therefor very dependent on the correct context.)



You have to call Scene.frame_set() instead of setting the property Scene.frame_current:


Only frame_set() updates animation data correctly. frame_current is mostly intended for reading access to determine the current frame.

Following example renders frame 0, 230, 99 and writes them to the disk as test_000.png, test_099.png and test_230.png.

import bpy
import os

# format integer with leading zeros
def formatNumbers(number, length):
    return '_%0*d' % (length, number)

# get the scene
scn = bpy.context.scene

# get the output path
output_path = scn.render.filepath

# set filename
filename = "test"

# set render frames
render_frames = [0, 230, 99]

# iterate through render frames
for f in render_frames:
    # set the frame
    # set filepath
    scn.render.filepath = os.path.join(
            filename + formatNumbers(f, 3) + ".jpg",
    # render opengl

# reset internal filepath
bpy.context.scene.render.filepath = output_path

Note: .jpg is only a placeholder and will be overwritten by the settings in the render panel.

  • $\begingroup$ Might be better to write a real answer that's helpfull for others too? $\endgroup$
    – p2or
    Mar 25 '15 at 9:58
  • $\begingroup$ I added some bits, feel free to improve it. $\endgroup$
    – CodeManX
    Mar 25 '15 at 10:34
  • 1
    $\begingroup$ @CoDEmanX really nice, will add my example to it, great teamwork :) $\endgroup$
    – p2or
    Mar 25 '15 at 10:35

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.