Normally the best way to go through this is to look at the Node Editor to help visualize what you need to do in script. So suppose we create a simple scene:
- Create a polySphere.
- Assign a new blinn material to the sphere.
- Assign a file texture node onto the color channel of the blinn material.
- (Optional) Add a file with transparency to the file texture node.
If you did each of those steps, you’ll note that there are two connections going out from the file node and into the material:
file1.outColor > blinn1.color
file1.outTransparency > blinn1.transparency
If you run the same steps with a PSDFileTex node, you’ll see the same connections.
So now we just need a script to do this and you were on the right track with listConnections. I’ve done a sample in Python.
import maya.cmds as cmds
def findMaterialConnections( texNode ):
matConnections = cmds.listConnections(texNode, destination=True, connections=True, plugs=True, type='lambert')
print matConnections
findMaterialConnections( 'psdFileTex1' )
# Result:
# [u'psdFileTex1.outColor', u'blinn1.color', u'psdFileTex1.outTransparency', u'blinn1.transparency']
You can see from the result that for each pair every even index, you get the source plug, and odd index represents the destination plug that the source plugs into. So let’s break down what my command call does:
[ul]
[li]It specifies the node I want to browse connections for as texNode.[/li][/ul]
[ul]
[li]It specifies destination=True to force it to return the attributes/nodes that are on the destination side of the connection. If the connection was driving the texture node, then you’d want to set this to false. But since we’re looking for outColor and outTransparency connections, the Node Editor shows that these drive the material.[/li][/ul]
[ul]
[li]It specifies connections=True, to make sure that we get the both the node and attribute of the texNode that is driving the connetion.[/li][/ul]
[ul]
[li]It specifies plug=True to make sure that we get both the node and the attribute of the material side.[/li][/ul]
[ul]
[li]Lastly, it specifies type=‘lambert’. This filters all connections to only look at connections at nodes of these types. Lambert is a base class for all software shader nodes so this will pickup other nodes like blinn, phong etc. If you want to capture other material nodes like dx11Shader or other plug-in nodes, you would need to run the command again with a different type and accumulate the results into a list.[/li][/ul]
From there, you should have all the info you need to do an in place change between file and psdFile nodes.
Hope this helps.