MEL: How to select a shading network by selecting one member of that network?

Hello everyone,

I’ve made a script that exports materials from a shading scene then imports and assigns the materials to alembics in a lighting scene. The only problem was it didn’t bring in the V-Ray displacement groups! So, instead of writing a script that exports and connects those displacement groups to their proper materials, I’d like to export a shading network by selecting it’s highest node in the network (the place2dTexture node), then select the rest of the network from there, and finally export that selection .

My big problem with solving this issue is I’m not quite sure what commands to use to select the rest of the network once I have the place2dTexture node selected. I usually use pickWalk when I want to move around a selection, but that doesn’t work in this case (as far as I know). I’ve attached an image to help clarify my question. Thank you!


And here’s my code so far:


// select all "place2dTexture" utilities
global proc SelectPlace2dUtilities()
    {
        string $nodesList[];
        
        $nodesList = `ls -type "place2dTexture"`;
        select -add $nodesList;
    }

you’ll want to take a look at the listHistory and listConnections commands.

http://help.autodesk.com/cloudhelp/2015/ENU/Maya-Tech-Docs/CommandsPython/listConnections.html

starting with the place2dtexture node you could just recursively list destinations until you run out of nodes.


def get_shader(node):
     return cmds.ls(*cmds.listHistory(node, f=True) or [], type='lambert)  or []

It has to return a list since it’s possible for one node to terminate in multiple shades. If you want the shadingGroup node, instead you could swap in ‘shadingEngine’ for ‘lambert’

Great! Thanks guys, I’ll take a look at these options and report back.

doh, I should have done that in mel

ls -type lambert listHistory -f 1 $node;