Wednesday, August 10, 2011

smSelectByShaderAndLayer.mel part 1

someone on a forum was looking for a simple way to select all the objects of a particular shader, but only of a particular layer. So, like select objects by shader, but only in selected layer.

I did a quick script on the boat on the way in and posted it on highend|3D .
for now it is here....
//--------------------------------------------------------------------
// selects the items based on shader and layer
// stephenkmann@yahoo.com
// right now based on mesh nodes only
global proc smSelectByShaderAndLayer (string $shader, string $layer)
{
string $SG[] = `listConnections -type "shadingEngine" $shader`;
print ("SG:" + $SG[0] + "\n");
string $objs[] = `sets -q $SG[0]`;

string $layerObjs[];
string $layerItems[] = `editDisplayLayerMembers -fullNames -query $layer`;
for ($li in $layerItems)
{
string $mshs[] = `listRelatives -type "mesh" -ad $li`;
$layerObjs = stringArrayCatenate ($layerObjs,$mshs);
}
$layerObjs = stringArrayRemoveDuplicates($layerObjs);

string $no[];
for ($obj in $objs)
{
if (stringArrayContains($obj, $layerObjs) !=1)
$no[`size$no`] = $obj;
}
string $selList[] = stringArrayRemove($no, $objs);

select -r $selList;

}
//--------------------------------------------------------------------


No comments:

Post a Comment