1
$\begingroup$

Is there any way to trigger a function call when a node link is created with another node? The called function should be able to access both the input and output nodes of the link created.

It would be helpful if possible in the Materials node tree and not the Compositor node tree.

$\endgroup$
  • $\begingroup$ AFAIK such a hook doesn't exist. What is the bigger picture, what are you trying to accomplish? $\endgroup$ – dr. Sybren Oct 1 '17 at 17:15
  • $\begingroup$ Actually, I wanted to run a function when image texture node is updated (linked) with some other node. The function would check the link and change the values of the current image texture node $\endgroup$ – Akash Hamirwasia Oct 1 '17 at 17:50
  • $\begingroup$ But to what purpose? $\endgroup$ – dr. Sybren Oct 1 '17 at 17:59
  • $\begingroup$ Like checking if input is Color type or not and then changing color space of image texture node automatically to non color data or color $\endgroup$ – Akash Hamirwasia Oct 1 '17 at 19:27
  • $\begingroup$ This would be easier to implement as a cleanup pass after you've created the node tree. Just have a Python script go over all the connections and perform this cleanup. $\endgroup$ – dr. Sybren Oct 1 '17 at 21:34
1
$\begingroup$

If you are writing your own nodes: Yes! You can add an update-function wich can handle input-tests. Your update-function will be called on every change of the node, so on linking/unlinking it will be called. Here is how:

class MyNode(bpy.types.Node):
    bl_idname='MyNode'
    bl_label ='MyNode'
    # your update function must only take self
    def update(self):
        # your code here
        for skt in self.inputs:
            if skt.links:
                print("Input socket {} is linked".format(skt.name))

If you are using existent nodes: No, probably not. You simply can not overwrite the nodes own update-functions. They seem to be like a read-only-property returning a function to you. Setting them wont work, no matter what.

$\endgroup$
  • $\begingroup$ Thanks for the suggestion, I know that it is possible in Custom nodes but thought if it would be possible in default nodes. Probably not at this point in time. $\endgroup$ – Akash Hamirwasia Nov 29 '17 at 19:52
  • $\begingroup$ @AkashHamirwasia Yeah, sorry. I tried a LOT of things, doing really really nasty hacks, but solely from within python, I was not able to change the behaviour. I guess you could fix something up with cpython, but that would probably be way more hassle than it's worth. But perhaps you'd like to write a driver for this instead? Should be possible... Well, best luck and stuff. :-) $\endgroup$ – Teck-freak Dec 2 '17 at 1:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.