1
$\begingroup$

I am trying to toggle fullscreen and 3dview sidebar panels from python (shortcut 'shift+alt+space' and 'n' respectively). I found these commands, but I can't get them to work:

bpy.ops.screen.screen_full_area(True) # toggle full screen?
bpy.ops.wm.context_toggle(data_path="", module="") # toggle 3dview sidebar panels?

Any ideas on how I can do this?

EDIT: This post asks my exact question: https://blenderartists.org/t/show-sidebar-3d-print-toolbox-with-python-api/1241410/2 . The answer is an operator with this line in the execute method:

context.space_data.show_region_ui ^= True

But this doesn't work for me :-(

$\endgroup$

1 Answer 1

1
$\begingroup$

I managed to get it working by overriding the context. So if anyone is interested, here it is:

for area in bpy.context.window.screen.areas:
        if area.type == 'VIEW_3D':
            for region in area.regions:
                if region.type == 'WINDOW':
                    override = bpy.context.copy()
                    override['area'] = area
                    override['region'] = region
                    override['scene'] = bpy.context.scene
                    bpy.ops.screen.screen_full_area(override, use_hide_panels=True)   

for area in bpy.context.window.screen.areas:
        if area.type == 'VIEW_3D':
            for region in area.regions:
                if region.type == 'WINDOW':
                    override = bpy.context.copy()
                    override['area'] = area
                    override['region'] = region
                    override['scene'] = bpy.context.scene                      
                    bpy.ops.wm.setup_ui(override)  


class MYOPERATOR_OT_setup_ui(bpy.types.Operator):
    bl_idname = "wm.setup_ui"
    bl_label = "Setup UI"

    def execute(self, context):
        context.space_data.show_region_ui = True # Opens sidebar in 3d viewport
        context.space_data.region_3d.view_perspective = 'ORTHO' # 'PERSP', 'CAMERA'. Set 3d viewport to othorgonal
        
        return {'FINISHED'}

The operator needs to be registred of cause.

$\endgroup$

You must log in to answer this question.

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