Select Faces on Object by Material in Maya

Jun 28, 2022

Selecting faces on an object in Maya by material is easy. Hold down right mouse button on the material then click "Select Objects with Material." This selects faces on all objects in the scene however. Here's a script to select faces on a single object by it's material. Select object then shift select material in hypershade then run script.

string $sel[] = `ls -sl`;
if (size($sel) < 2 || size($sel) > 2) {
    error("Select an object, shift-select one material in Hypershade, then run this script");
}
string $object = $sel[0];
string $mat = $sel[1];
string $objects[];
hyperShade -o $mat;

select -tgl $objects;
$objects=`ls -sl`;

select -cl;

for($i=0; $i<size($objects); $i++)
{
    string $temp = `match "^.*\\." $objects[$i]`;
    if (size($temp) > 0) {
        string $check = `substring $temp 1 (size($temp) - 1)`;
        if($check == $object)
        select -tgl $objects[$i];
    }
}