I am a beginner with python, and prompted by my previous question, I was trying to set viewport shading to Solid and View Only Render to True with python. (The goal being to get the script in that answer to work entirely from python without any need for interaction with the GUI)
From what I can understand from a lot of searching, is that the cursor needs to be in the 3D view for that object to be active.
It is suggested here to loop through all the areas to do this.
I tried doing this and setting the view to camera, shading to solid, and view only render to true.
However, what actually happens is that the view is set to camera, and the image is rendered without changing view only render to True.
Modified version of the script originally written by Adhi in my previous question, with changes suggested by Aldrik in the answer below:
import bpy import sys # read argument from sys.argv from bpy.app.handlers import persistent @persistent def do_render_opengl(dummy): for area in bpy.context.screen.areas: if area.type == 'VIEW_3D': area.spaces.region_3d.view_perspective = 'CAMERA' #if area.type == 'SpaceView3D' : area.spaces.show_only_render = True area.spaces.viewport_shade = 'SOLID' bpy.data.scenes.render.filepath="/tmp/glrender.png" bpy.ops.render.opengl(animation=False, write_still=True, view_context=True) bpy.ops.wm.quit_blender() bpy.app.handlers.load_post.append(do_render_opengl)
I have changed the script with Aldrik's improvements, but when I run it with
blender -P gl_render.py example.blend, It returns:
File "/home/gandalf3/Blender/Opengl_render.py", line 11, in do_render_opengl area.spaces.show_only_render = True AttributeError: 'SpaceInfo' object has no attribute 'show_only_render'
It seems that it's still not in the right context?