0
$\begingroup$

In 2.8, I am having difficulty adapting a code sample written for Blender/Python 2.63. The intent is to save images of a scene using python. The code was sourced from this post.

In 2.8, the code throws an error on the following line. The error message is 'AttributeError: 'SpaceView3D' object has no attribute 'viewport_shade''

area.spaces[0].viewport_shade = 'RENDERED'

The full code snippet is here:

for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        area.spaces[0].viewport_shade = 'RENDERED'

bpy.context.scene.render.image_settings.file_format='JPEG'
bpy.context.scene.render.filepath = ".pic%0.2d.jpg"%i
bpy.ops.render.render(use_viewport = True, write_still=True)
$\endgroup$
1
$\begingroup$

The line to set the viewport shading needs to change from

area.spaces[0].viewport_shade = 'RENDERED'

to

area.spaces[0].shading.type = 'RENDERED'

since Blender 2.8's API has replaced viewport_shade. Here you can find the documentation of the Area, AreaSpaces, SpaceView3D (if the space is of type 'VIEW_3D') and View3DShading.

Although I'm wondering why you'd want to set the viewport shading if you intend to actually render the scene. In case this really is what you want I'd suggest getting the active space, which will be the one currently displayed.

for area in bpy.context.screen.areas: 
    if area.type == 'VIEW_3D':
        space = area.spaces.active
        space.shading.type = 'RENDERED'
$\endgroup$
  • $\begingroup$ Thanks for your help ... both suggestions work. As far as why I chose the first, I am a noob and am as of yet still developing an understanding of this rather complicated piece of software ;) $\endgroup$ – vndep Jul 26 at 20:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.