Using python, how do you get the last image node downstream of the principled node's diffuse input socket.

For example if there's an unknown number of other nodes between the texture image node and the principled's diffuse input.


  • 1
    $\begingroup$ The nodes connected to the base color input form a tree, there can be several texture nodes at the same depth. What exactly do you consider to be the last node? $\endgroup$ – Robert Gützkow Nov 19 '19 at 17:47
  • $\begingroup$ the one which has the most nodes between it and the principled diffuse socket. So maybe create a dictionary which stored the found image node name as the key, and the number of nodes upstream as the value. Then order the dictionary based on value and pick the one with the highest value. If there are multiple with the same value, then just pick any of those. $\endgroup$ – user3597862 Nov 19 '19 at 18:14

Your Answer

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

Browse other questions tagged or ask your own question.