2
$\begingroup$

I want to detect context changes when switching between different tabs in the property editor.

How should I set up msgbus or how to get the context through the Python API?

enter image description here

$\endgroup$

1 Answer 1

1
$\begingroup$
import bpy

# Any Python object can act as the subscription's owner.
owner = object()

subscribe_to = bpy.types.SpaceProperties, 'context'


def msgbus_callback(*args):
    print(args)
    current_tab = bpy.context.screen.areas[0].spaces.active.context
    print(f'Current Tab: {current_tab}')


bpy.msgbus.subscribe_rna(
    key=subscribe_to,
    owner=owner,
    args=(1, 2, 3),
    notify=msgbus_callback,
)
$\endgroup$
1
  • $\begingroup$ oh , thanks ! I get it !The 'subscribe_to' should be a combination of structure and property $\endgroup$
    – fage
    Nov 9, 2023 at 7:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .