1

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 Answers1

0

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' break

Render image through viewport

bpy.ops.render.opengl(write_still=True)

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'?

Math_Max
  • 183
  • 10
  • 1
    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) – batFINGER Aug 25 '20 at 12:50
  • 1
    If you run this code without the background mode, it will open Blender and it will work. – Math_Max Aug 25 '20 at 12:58
  • 2
    See Question: "while running Blender as Python module" – batFINGER Aug 25 '20 at 12:59