I am looking for a method to read various variables from a shader node from within my python script.
In order to get for instance a texture map filepath from the BSDF I use something like:
if (Material): bsdf_node = Material.node_tree.nodes.get('Principled BSDF') if (bsdf_node): try: link = node.links link_node = link.from_node texture = link_node.image.name except: print("[%s] no diffuse texture set."%(Material.name),True,False)
This works fine, and I extended the program for various other inputs of the BSDF shader. My problem is that I try to extract the same information from a connected normal map. In other words I would like to:
- find the connected ‘Normal Map’ node
- save the normal map strength to a variable
- find the connected ‘Image’ node, which will hold the normal map
- Extract the filename from the image node.
Of course, I could use Material.node_tree.nodes.get(‘Normal Map’), however I would like to make sure that I am dealing with a node that is connected to my Principled BSDF node.
I can’t really figure out how to navigate from node to node and hope you could give me pointers.