0
$\begingroup$

I've set my timeline's Start and End frame to $1$. For some reason bpy.ops.render.render(animation=True) works but not when animation=False. Why does it not work? No errors. When I press Run Script it seems to be rendering but there is no output image generated.

def render(image_name):
    scene.frame_current = 1
    scene.frame_set(1)
    scene.render.filepath = f'/path/to/file/{image_name}.png' 
    scene.render.image_settings.file_format = 'PNG'
    bpy.ops.render.render(animation=True)

render("myimage")
$\endgroup$

1 Answer 1

2
$\begingroup$

You need to specify write_still=True.

When the animation argument is set to False, it tells Blender to render a single frame instead of an animation. The write_still=True argument is necessary in this case, as it tells Blender to write the rendered frame to disk. Without this argument, Blender will not save the rendered image. When you set animation=True, the write_still argument is not needed because Blender will save each frame of the animation to disk automatically.

It is also worth noting that you can also use bpy.context.scene.frame_set(frame_num) to set the frame you want to render, before calling bpy.ops.render.render(animation=False, write_still=True)

def render(image_name):
    scene.frame_current = 1
    scene.frame_set(1)
    scene.render.filepath = f'/path/to/file/{image_name}.png'
    scene.render.image_settings.file_format = 'PNG'
    bpy.ops.render.render(animation=False, write_still=True)

render("myimage")
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .