Does anyone know the operators for 3dView display settings?

I’m having trouble locating the operators for toggling the “Only Render”, “Outline Selected”, “All Object Origins”, etc.

Hovering over the buttons yields: SpaceView3D.show_only_render, etc.
I assumed it would be amongst the bpy.ops.view3d operators but I could not find it. And bpy.ops.view3d.show_only_render, etc. doesn’t work. I’m out of ideas and pretty inexperienced in python, any thoughts?

Cheers!

You have to be in the adequate context to have access to these


import bpy

screen = bpy.context.screen

v3d = False
# get spaceview_3d in current screen
for i in screen.areas:
    if i.type == 'VIEW_3D':
        v3d = i.active_space

if v3d != False:
    # found v3d
    v3d.show_only_render = False # for example

or for an operator invoked from the view3d context (button or menu):


import bpy

class VIEW3D_toggle_only_render(bpy.types.Operator):
    bl_idname = "toggle.only_render"
    bl_label = "Toggle only render"

    def execute(self,context):
        v3d = context.space_data

        if v3d.show_only_render == True:
            v3d.show_only_render = False
        else:
            v3d.show_only_render = True
        
        return {'FINISHED'}

def register():
    bpy.utils.register_class(VIEW3D_toggle_only_render)

def unregister():
    bpy.utils.unregister_class(VIEW3D_toggle_only_render)

if __name__ == "__main__":
    register()

Beautiful! That’s exactly what I needed. Thanks!