I need to know if the active node of a node changes. I have found this example for the active object, that works very well:
import bpy
def msgbus_callback(*arg):
# in console will be print selected_objects
print(bpy.context.selected_objects)
# you can do something
def subscribe_to_obj():
bpy.msgbus.subscribe_rna(
key=(bpy.types.LayerObjects, 'active'),
owner=bpy,
args=('something, if you need',),
notify=msgbus_callback
)
if name == "main":
subscribe_to_obj()
I try to do something like that for the active node in node tree, but it doesn't work:
import bpy
def msgbus_callback(*arg):
# in console will be print selected_objects
print(bpy.context.selected_objects)
# you can do something
def subscribe_to_active_node():
bpy.msgbus.subscribe_rna(
key=(bpy.types.Nodes, 'active'),
owner=bpy,
args=('something, if you need',),
notify=msgbus_callback
)
if name == "main":
subscribe_to_active_node()
A way could be observing if the operator bpy.ops.node.select() is called, but I don't know how.