I need to save viewport image while running Blender as Python module.This is required because I need real time updated ( only available on viewport )?

Does somebody now is it possible?


1 Answer 1


Yes, you can save images rendered from the viewport.

# Set save path
sce = bpy.context.scene.name
bpy.data.scenes[sce].render.filepath = "./image.png"

# Go into camera-view (optional)
for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        area.spaces[0].region_3d.view_perspective = 'CAMERA'

# Render image through viewport

Here are all the different python rendering commands.

A tip for finding out python commands: go into Blender, then Edit > Preferences > Interface tab > check Python Tooltips box. Then you can hover your cursor over any button and the python code command will display as well.

By the way: I am not sure what you mean by 'real-time updated'?

  • 1
    $\begingroup$ AFAIC this is wrong. The OP is using bpy as a python module, in which case it is running without a UI (headless) Same deal using background mode blender -b. Trying to use bpy.ops.render.opengl() will result in the error RuntimeError: Error: Cannot use OpenGL render in background mode (no opengl context) $\endgroup$
    – batFINGER
    Aug 25, 2020 at 12:50
  • 1
    $\begingroup$ If you run this code without the background mode, it will open Blender and it will work. $\endgroup$
    – Math_Max
    Aug 25, 2020 at 12:58
  • 2
    $\begingroup$ See Question: "while running Blender as Python module" $\endgroup$
    – batFINGER
    Aug 25, 2020 at 12:59

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