bpy.types.Node: socket_value_update(context)

Hi all,

I’ve been playing around with nodes lately (using Atom’s Blendgraph addon), and I have a simple (I think) question: how can my node be notified of changes on the (input) sockets? An example:


So I’d like to have some way of doing something when, eg, the Scene input in the Object Repeater changes – either by the user deleting the link or selecting another scene in the Scene Node. The only thing I could find is the socket_value_update() function on the node. I thought it would be a matter of ‘overriding’ this function (like you do with the update() function), but that doesn’t seem to work:


class bgObjectRepeaterLRSNode(Node, bgCustomTreeNode):
    ''' ObjectRepeaterLRS Node '''
    bl_idname = 'bg_ObjectRepeaterLRSNode'
    bl_label = 'Object Repeater LRS Node'
    bl_icon = 'NODE'
    # ...
    def init(self, context):
        self.inputs.new('bgStringInputSocketType', "Scene", "Scene2")
        # ...
    
    def update(self):
        print("--", "update:")
        # ...
                
    def socket_value_update(self, context):
        print("--", "socket_value_update:")
        # ...



Any ideas on how to do this?
g

There is an intercept already in place in the socket code. In your example, in the image, you are connecting to a String type custom socket so the intercept would be inside bg_socket_String.py.

When you plug something in using Blendgraph the icon on the input changes.


    def draw(self, context, layout, node, text):
        if self.is_linked:
            layout.label(text,icon='CONSTRAINT')
        else:
            layout.label(text,icon='TRIA_RIGHT')

Even though it is just a draw routine, it acts like an update as far as connection is concerned. But any code placed in the draw would affect all nodes system wide that use strings.

You could, of course, clone the socket code and make your own version of the custom string type.

Thanks for the tips, Atom. I’d like to avoid making my own string socket. I’d rather not use the draw() routine to hook this up, neither, as it would generate a lot of overhead, as the draw() function is called many times without anything happening to the nodes.

Maybe I should hook it up to the update() function in the node itself, which would still generate some overhead, but a lot less than using the draw() method. Also, I’d like to implement this scene changing code only once – I don’t want to have to deal with it everytime I write a generator node.

So maybe I should create a bgGeneratorNode that implements this and derive my object repeater from that. That probably means keeping an ‘old_value’ in there, so I can determine wether the input has actually changed. Hmm, that may be worth a shot…

Any idea what socket_value_update() is for?