Workspaces in Blender are saved sets of work areas (windows of the desired type). Typically, switching between them is done by clicking on the tab with the name of the workspace at the top of the Blender UI. We can also switch between workspaces using the Blender Python API.
We can get a list of all available workspaces using the following command:
1 2 3 |
bpy.data.workspaces[:] # [bpy.data.workspaces['Animation'], bpy.data.workspaces['Compositing'], bpy.data.workspaces['Geometry Nodes'], ...] |
The currently active workspace is stored in the “context.window.workspace” parameter:
1 2 3 |
bpy.context.window.workspace # bpy.data.workspaces['Layout'] |
To switch to the desired workspace, we need to assign this parameter the value of the required workspace:
1 |
bpy.context.window.workspace = bpy.data.workspaces['Animation'] |
Workspaces can be imported from external Blender files using the “bpy.ops.workspace.append_activate” operator.
For example, to import the “Shading” workspace from the startup file, we need to execute this operator as follows:
1 2 3 4 |
bpy.ops.workspace.append_activate( idname='Shading', filepath=bpy.utils.user_resource('CONFIG', path='startup.blend') ) |
The specified workspace will be imported into the current session and Blender will switch to it.
didn’t know you can import workspaces, it gives me ideas, thanks !