Select random faces in Maya is a very handy mel script tool. Since Maya doesn’t have any built-in tools for that purpose. This mel script is going to save us a lot of time.
The Author of the script is Byterunner. Unfortunately, I haven’t found any other information, or links to add to his/her work.
So instead of selecting randomly all the faces in a geometry in Maya, and losing a lot of time, especially if we are working on a high-polygon mesh, we could use this mel script.
Select random faces in Maya (mel script):
What basically does is randomly select a percentage of faces we specify of an object in Maya. Each time we run the script, the faces that will be selected will be random, every time, which is cool.
In order to use it, we have to select an object or more and run the script in Maya from the Script Editor in the proper code language (mel).
Note: The percentage selection of faces is per object, for instance. If we select two or more objects and run the select random faces mel script, the percentage selection will be per object and not for our overall selection objects.
You can find the mel script below:
string $faces[] = {};
float $selectPercent = 0.10;
for($each in `ls -sl`)
{
int $nFaces[] = `polyEvaluate -f $each`;
int $sFaces = $nFaces[0] * $selectPercent;
for($i=0;$i<$sFaces;$i++)
{
string $rFace = $each + ".f[" + int(`rand 0 $nFaces[0]`) + "]";
while(stringArrayContains($rFace, $faces) == 1)
{
$rFace = $each + ".f[" + int(`rand 0 $nFaces[0]`) + "]";
}
$faces[size($faces)] = $rFace;
}
}
select -r $faces;
We have one parament we can change depending on our goal, and that’s the percentage of face selection. Which is the second line of the above script (float $selectPercent = 0.10;).
0 means there will be no face selection at all and 1 means all the faces will be selected. By default, the script is set at 0.10 which means 10% of faces will be selected for the selected object(s) in Maya.
Additionally, it’s a good idea, for ease of access, to put the script on a shelf in Maya to reuse it when you need it.
You may be interested in the below mel scripts in Maya as well:
- Combine curves in Maya as one piece through a simple line of MEL script
- Create facial GUI controls with free mel script in Maya
- Joint splitter mel script tool for Maya (time-saver for rigging)
Let’s try out this mel script in Maya, to see it in action, with a simple polygonal sphere geometry.
Select random faces in Maya:
Select the sphere mesh and open up the Script Editor by going to Windows – General Editors – Script Editor. Navigate to a mel script tab, and paste the above mel script.
In this example, we will set the percentage to 0.35 (approximately 1/3 faces of our object). Highlight the whole mel script and hit ctrl + enter to execute the script.
As we can see, our select random faces in Maya mel script have selected approximately 1/3 of the faces of our sphere.
Lastly, we can combine this mel script with the technique to add randomness to our geometry in Maya. In that way, we can only add randomness to a percentage of faces in our geometry, and not in the whole mesh.
One Response