Set a choosed workspace to active?

hello i want to create a shortcut for each and every workspace i have made , and i cant find any bpy code or DNA text to help me achieve my goal … any help ? thanks :slight_smile:

bpy.context.window.workspace = bpy.data.workspaces["MyWorkspace"]
1 Like

Hi,
im struggling a lot to find a way to force the UI refreshing, since the solution proposed only works if called once, but if you concatenate two calls and want to force a UI update after the first one you wont see the change.
ive been looking and trying different methods extensively but havent found a way.
The documentation to this regard is rather poor, i.e: no description about the “tag_redraw” method at all, what it does, when it is triggered…etc. Tried also to use an operator and call bpy.ops.wm.redraw_timer() with no success.

Any help or hint would be much appreciated,
Thanks!

It’s not supported to immediately refresh the UI. That happens delayed after scripts (and built-in operators) finish executing. Ensuring state remains valid and avoiding crashes would be quite difficult if we supported that.

Hi Brecht,
I understand. I made a quick test that switches the context workspace to “Modeling” and then using a modal operator with a timer, switches it back to “Scripting” after a couple of seconds and it works: i can see the changes in the UI during the whole script.
But im thinking if that’s the “correct”, “a la” Blender, style to achieve things like these. Should i define every time it is needed, a modal operator and attach a timer to it that would trigger the UI change just to be able to refresh the UI? Ive been searching the source code trying to identify the pieces of code that actually redraw the UI just to mimick it in my scripts but wasnt able to find anything. Would that be something “less boilerplate” than using modal operators with timers?
Thanks a lot in advance.

The right way to implement this I don’t know without more context about why you need to show multiple workspaces after each other.

The few scenarios I can think of where that makes sense, seem reasonable to implement with operators and timers.