I want to write a function, which will be called after changing the workspace.
I thought, that i can find workspace change event in bpy.app.handlers
, but it looks like where is no such handler here… What can I do?
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.
Sign up to join this communityI want to write a function, which will be called after changing the workspace.
I thought, that i can find workspace change event in bpy.app.handlers
, but it looks like where is no such handler here… What can I do?
Use msgbus
and subscribe to the workspace
property of the window class: https://docs.blender.org/api/current/bpy.types.Window.html#bpy.types.Window.workspace
import bpy
handle = object()
# Triggers when window's workspace is changed
subscribe_to = bpy.types.Window, "workspace"
def notify_test(context):
print(context.workspace.name)
context.workspace.status_text_set("Hello: {}".format(context.workspace.name))
bpy.msgbus.subscribe_rna(
key=subscribe_to,
owner=handle,
args=(bpy.context,),
notify=notify_test,
)
bpy.msgbus.publish_rna(key=subscribe_to)
Output:
Layout
Scripting
Texture Paint
...
https://docs.blender.org/api/current/bpy.msgbus.html