1

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.

Duarte Farrajota Ramos
  • 59,425
  • 39
  • 130
  • 187
frantz
  • 11
  • 2
  • You might want to try the ``bpy.app.handlers``` as described by this answer. I'll see if I can figure out your specifics. – james_t Nov 29 '23 at 18:39
  • Thanks a lot for your comment. The problem is that selecting a node in a nodetree doesn't update the depsgraph ... – frantz Nov 30 '23 at 06:50
  • A way could be observing if the operator "bpy.ops.node.select()" is called, but I don't know how – frantz Nov 30 '23 at 06:53
  • Polling. Simply check on a short interval if currently active (selected? That's a different thing) has changed since the last check. – Markus von Broady Nov 30 '23 at 10:55

0 Answers0