Fullscreen after changing workspace

I’m trying to change my workspace then make the VIEW_3D in that workspace fullscreen,
using this as a reference this is what I’ve come up with so far:

bpy.context.window.workspace = bpy.data.workspaces[workspace_name]
for screen in bpy.data.workspaces[workspace_name].screens:
    window=bpy.context.window_manager.windows[0]
    for area in screen.areas:
        if area.type == 'VIEW_3D':
            override = {'window': window, 'screen': screen, 'area': area}
            bpy.ops.screen.screen_full_area(override)
            break

but this doesn’t work and crashes blender,
how do I achieve what I’m trying to do?

Blender 3.2+ versions now uses temp_override().

import bpy

workspace_name = 'Layout'

bpy.context.window.workspace = bpy.data.workspaces[workspace_name]
for w in bpy.context.window_manager.windows:
    for a in w.screen.areas:
        if a.type == 'VIEW_3D':
            with bpy.context.temp_override(window=w, area=a):
                bpy.ops.screen.screen_full_area()
            break
1 Like