# How to enable ambient occlusion in the Viewport with Python?

I have been trying to access different functionality in blender using python and I stumbled upon this really difficult problem. I can’t find out how to enable or disable the Ambient Occlusion using Python in the viewport. I have looked at the info panel that records the Python actions and it returns a weird (null) method. I did some research on the python function and found their operations, but I can’t figure out how to get Blender to recognize it. I checked all the buttons around it but they didn’t lead to any conclusion. I am at a complete loss of what to do and any help would be awesome

These types of properties are properties of the 3D view, and so that's what you need to access to access them.

This following code accesses the Ambient Occlusion property but this is dependent on how your screen is laid out:

bpy.data.screens['Default'].areas[4].spaces[0].fx_settings.use_ssao = True


'Default' relates to the current screen layout and 'areas' to the various views that might be open (we need the 3D view). The problem with this is if the screen layout changes then the 3D view might not be in areas[4] anymore (as the list of areas will have changed). To solve this we can instead use the following code which will loop through the areas until we find a 3D view:

for area in bpy.context.screen.areas:
if area.type == "VIEW_3D":
area.spaces[0].fx_settings.use_ssao = True

• You guys are awesome! I honestly couldn't get this to work, but this is exactly what i was looking for. Thanks again! – Ryan Grzesiak Aug 26 '15 at 12:57
import bpy

for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
for space in area.spaces:
if space.type == 'VIEW_3D':
space.fx_settings.use_ssao = True


something like this. You either have a reference to a window and that will let you access 'space' directly, or you can iterate over all open VIEW_3D areas and set it that way. break early if you need to.