The code below works flawless, if e.g. triggered by a menu button in a 3D view.
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
for space in area.spaces:
if space.type == 'VIEW_3D':
space.viewport_shade = 'BOUNDBOX'
However, if I bundle it into a function and hook it to a handler, it returns a NoneType error:
@persistent
def allBound(dummy):
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
for space in area.spaces:
if space.type == 'VIEW_3D':
space.viewport_shade = 'BOUNDBOX'
bpy.app.handlers.render_pre.append(allBound)
Returns:
AttributeError: 'NoneType' object has no attribute 'areas'
How to solve this?