I am trying to access and change the viewport overlay panel options in Object Mode using python. Specifically, I want to toggle the "Face Orientation" checkbox with python:

enter image description here

I thought I am able to access it using:


Turns out this does not work and raises an AttributeError.

Blender Python API Error

What do I have to do?


1 Answer 1


The overlay attribute is part of the bpy.types.SpaceView3D. Therefore you first need to iterate over the areas of the current screen and find the 3D View. Then you can search for the space in the area that has the type attribute set to 'VIEW_3D' and is therefore of type bpy.types.SpaceView3D. If such a space exists you can access the overlay and through it show_face_orientation.

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.overlay.show_face_orientation = not space.overlay.show_face_orientation

Note that you cannot set the overlay option using the code above if you don't have an area with the 3D View open in the current screen.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .