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