Access to workspace areas

Hey guys, In blender 2.79 I could edit a layout’s areas through code and by layout name (without having them active):

for area in bpy.data.screens["Animation"].areas:
    if area.type == 'VIEW_3D':
        for spaces in area.spaces:
            if spaces.type == 'VIEW_3D':
                area.spaces.active.clip_start = 0.1

However I don’t know how to access workspace areas in 2.80
Any help?

Each workspace has its own screen in bpy.data.screens. They’ll be all be named ‘Default’.

But instead of using that, you can access the screen used by the workspace by:

bpy.data.workspaces['my_workspace'].screens[0]

Then you just loop through the screen’s areas like you did before.

Thank you so much, saved me a sleepless night there haha.

This works but i’m just putting it here in case someone needs it or if someone points out I made a mistake:

for area in bpy.data.workspaces['my_workspace'].screens[0].areas:
    if area.type == 'VIEW_3D':
        for spaces in area.spaces:
            if spaces.type == 'VIEW_3D':
                area.spaces.active.clip_start = 0.1
2 Likes

I would like to know how i can switch workspaces like i did pre 2.80
I made an addon which used this code to switch using preset names.

bpy.context.window.screen=bpy.data.screens[self.layoutItems1]

My addon makes it possible to add shortcuts and popup menu to quickly switch screenlayouts or workspaces as they are called now

Using the code which worked i now get this error.
RuntimeError: class SCREEN_OT_set_layout, function execute: incompatible return value , str(, Function.result expected a set, not a NoneType)

No matter how i change the code the output error is always the same. I tried this using info given earlier

bpy.context.window.workspace.screens = bpy.data.workspaces['my_workspace'].screens[self.layoutItems1]

Okay after lots of fiddling i got it to work again :slight_smile:

I know use this line and am able to switch workspaces again with the menu and shortcuts
bpy.context.window.workspace = bpy.data.workspaces[self.layoutItems1]

1 Like

PS i dropped my addon on GitHub and also added quick render menu access. This is so much faster now switching workspaces :slight_smile:

1 Like