Selecting shader node given connected texture node

This problem has me going around in circles. I have a script that I am making that will compare two texture paths and if they are the same select the faces assigned to one shader and assign them to the other.

The problem comes in when trying to select the faces assigned to the shader that is related to the first texture node.

It is not working currently because i can not find a command to transfer the selection to the shader from the texture node. I have tried the pickWalk command, the connectionInfo, listHistory -future, and have found the best results with listConnections -destination on. Unfortunately when I use the listConnections i get a materialinfo node as well as a defaultTextureList node, which are further down the hierarchy somewhere.

This portion of the code currently looks like this:

select $texNode[$j];
select -ne listConnections -source 0 -destination 1 texNode[j];
//$shader = connectionInfo -dfs texNode[j];
$shader = ls -sl; //ls -sl -typ shader;
print $shader;
hyperShade -o $shader;

and the objects selected look like this...

materialInfo4
defaultTextureList1
(desired shader)

The second portion is easy because maya has a way to assign a shader directly to the selection from the texture node.

//assigns faces from first shader to second shader
hypergraphAssignTextureToSelection $texNode[$k];

So, any number of solutions would be nice,

1) a way to limit the listConnections function to only the first direct connection, which you can see above I was trying to do with the connectionInfo but had to comment out.

2) a way to limit the selection to only a certain type when it is read into the $shader variable after the listConnections, which i also tried but commented out because i could not find the specific type for a shader.

3) a way to query the faces assigned to a given shader according to the texture node itself, in much the same way that the hypergraphAssignTextureToSelection assigns with just the texture node specified

Anyone who knows specifics on any of these solutions, or any help at all would be greatly appreciated.

Thanks,
the bird

Okay, a few things to remember about working with shaders. Maya shading groups are nothing more than specialized selection sets. Since they are sets, you can use the sets command and all of its functionality with them to manipulate membership. I recommend avoiding any of the hypershade commands. These are essentially macros and leave you a little bit blind along the way since it doesn't have very good return info. Better to know what is going on on the lowest level, I think.

Let's take a look at your exact issues in depth.

To go from a texture node to its associated material node:

listConnections -s 0 -d 1 -type lambert [fileNodeName];
or
listConnections [fileNodeName].outColor;

Though the type mask on the first one says "lambert" this seems to return any material type.
You will probably want to then move up to the shading group so you can use the sets command to assign membership.

listConnections -s 0 -d 1 -type shadingEngine [materialName];

Now that you have your shading group(s) for that texture, you can get all the faces with it is assigned to with

sets -q [shadingGroup];

I hope this is enough to get you rolling. If not come on back.

--JeffD

Thank you very much... limiting the type to lambert took care of it...

Is there a list anywhere of all the available types that can be input when a type flag is set? I can't seem to find them in the command reference.

thanks again,
bird

they are the node type lisitngs in 'node and attrib ref'.

nodeType, to q a node's type.

I usually figure out node types as I need them. To get it I usually select the object and use...

ls -sl -st;

This returns the object name and node type.

--JeffD