# Setting the Context Window Screen Layout Explicitly in BPY

In 2.7 you could set the active screen layout with, e. g. for "UV Editing":

bpy.context.window.screen=bpy.data.screens['UV Editing']


This no longer seems to have any effect in 2.81.

Some new means to make it kick in?

Incidentally, does 2.8+ support a shortcut to switch it explicity? I had defined my own operator in a startup script just to do so, which used the line above.

The current workspace can be changed to the UV Editing workspace through:

bpy.context.window.workspace = bpy.data.workspaces['UV Editing']


This assumes that a workspace named UV Editing exists. In order to check for the case where it doesn't exist, use bpy.data.workspaces.get('UV Editing') instead and verify that the returned value is not None.

The current area type can be changed through bpy.context.area.type. In order to change to the UV editor you can use:

area = bpy.context.area
area.type = 'IMAGE_EDITOR'
area.ui_type = 'UV'


Although it's not documented in the manual you can also just assign the ui_type and it will automatically change the type as well.

bpy.context.area.ui_type = 'UV'


If you want to change a different area than the current one, you can iterate through bpy.context.screen.areas.

• That will change just the one area, i. e. window, within the screen layout you're in. What we want is to change bpy.context.screen entirely, to a different pre-set layout. as per the tabs at the top of the screen. – Blitzen Dec 1 '19 at 18:56
• Sorry for the misunderstanding. So you want to change to the UV Editing workspace? The concepts and API changed a little from 2.79. – Robert Gützkow Dec 1 '19 at 19:02