Skip to content

Instantly share code, notes, and snippets.

@SEVEZ
Last active September 6, 2015 21:18
Show Gist options
  • Save SEVEZ/8722f8c622da22306bfa to your computer and use it in GitHub Desktop.
Save SEVEZ/8722f8c622da22306bfa to your computer and use it in GitHub Desktop.
Select one face on an object. Run MatFaceFinder. This script will select all of the faces strictly on that object which share the same material assignment as the first face.
// SCRIPT NAME: MatFaceFinder.mel v1.1 (Maya2009 version)
// AUTHOR: Thomas Hamilton
// LAST UPDATED: November 16, 2009
// www.thomashamilton.org
//DESCRIPTION:
//Select one face on an object. Run MatFaceFinder. This script will select all of the faces
//strictly on that object which share the same material assignment as the first face.
//SETUP:
//Close Maya.
//Copy MatFaceFinder.mel to My Documents\maya\2009\scripts. Open Maya.
//Type MatFaceFinder in the command line, highlight, and middle mouse drag to your shelf.
global proc MatFaceFinder()
{
string $SelectedFace[]= `ls -sl -fl`;
string $ShapeNode[];
//Here we tokenize the selected face to determine what object the face is a member of.
tokenize $SelectedFace[0] "." $ShapeNode;
string $facetSG = "";
//The hypershade command finds which shading group is assigned to the selected face.
//(this command replaces the old getFaceSG procedure)
$facetSG = `hyperShade -smn ""`;
string $Shader[] = `ls -sl`;
//Now that we know the Shading Group, we select all the faces in the scene that have that shader assigned to them.
//Unfortunately, if an object has only that shader and no others assigned to it, it does not return the face names,
//but the object transform name. So we send all selected items through a loop that tests whether each of the selected
//items has a "." in its name. If not, then we know that it is an object transform, and not a face selection. In those
//cases we select the transform, convert it to faces, and update the original string array by replacing the transform name
//with the entire objects face selection. We can then reselect the entire array after the loop, leaving us with only
//faces being selected.
hyperShade -objects $Shader[0];
string $ObjectAllFaces[] = `ls -sl`;
for ($i=0;$i < size($ObjectAllFaces);$i++ )
{
if (`gmatch $ObjectAllFaces[$i] "*.*"` == 0)
{
select $ObjectAllFaces[$i];
ConvertSelectionToFaces;
string $NewSelectedFaces[] = `ls -sl`;
$ObjectAllFaces[$i]= $NewSelectedFaces[0];
}
}
select $ObjectAllFaces;
/////////////////////////////
string $ObjectFinFaces[];
clear $ObjectFinFaces;
select -cl;
//Here we are going to check to see which faces we now have selected are also members of the original object, (the object
//upon which we made our very first single face selection). We tokenize the new list of faces to give us its shape node,
//and compare that to the original shapenode. If they match, then we store that group of faces into a new array, and once
//we have them all, we make a selection of the entire array, giving us a selection of only the faces, on the same object,
//with the same shader as our original face.
for ($i=0;$i<size($ObjectAllFaces);$i++)
{
string $ShapeNodeDummy[];
tokenize $ObjectAllFaces[$i] "." $ShapeNodeDummy;
if ($ShapeNode[0] == $ShapeNodeDummy[0])
{
string $CurrentFace[] = {$ObjectAllFaces[$i]};
appendStringArray($ObjectFinFaces, $CurrentFace, 1);
}
clear $ShapeNodeDummy;
}
select $ObjectFinFaces;
doMenuComponentSelection($ShapeNode[0], "facet");
}
MatFaceFinder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment