Eevee in Blender 2.8 is so awesome that just saving the viewport (view > Viewport Render Image) looks really good.
I'd like to save the viewport periodically from a timer script using the operation bpy.ops.render.opengl()
Here's some code that gets close:
# viewport_loop.py
import time, bpy, functools
def render():
timestr = time.strftime("%Y%m%d-%H%M%S")
print(timestr)
# uncomment below line for error...
# bpy.ops.render.opengl(animation=False, sequencer=False, write_still=True, view_context=True)
def loop(data):
render()
return 2.0
if __name__ == '__main__':
bpy.app.timers.register(functools.partial(loop, ""), first_interval=5.0)
I'm calling the script from the command line on osx
blender ./file.blend --python ./viewport_loop.py
When the render line is uncommented I'm getting the error:
RuntimeError: Operator bpy.ops.render.opengl.poll() failed, context is incorrect
bpy.ops.render.opengl() does work, but not in this timer (or in a thread incidentally).
Any thoughts, is there any way to override the context for this operation?
Perhaps around the 'view_context' parameter of bpy.ops.render.opengl() because I've seen in other answers that a context needs to be overridden. For example the following, which enlarges the viewport...
for window in bpy.context.window_manager.windows:
screen = window.screen
for area in screen.areas:
if area.type == 'VIEW_3D':
override = {'window': window, 'screen': screen, 'area': area}
bpy.ops.screen.screen_full_area(override)
break