Hi everyone,
Maya is usually pretty slow when you try to do something with a lot of components.
I wrote a simple MEL script (yeah I know it’s old) to separate objects based on the selected polygons.
My goal was to get the result(s) fast, with the correct name, maintain the hierarchy, the script should work on multiple objects at the same time and check the selection against the total number of polygons for each object.
Maybe it’s not elegant, but it will do the job and it’s pretty fast. (Actually, this is the fastest separation script I found/tested so far.)
How to use it:
- Select the polygon faces (It works on multiple objects as well)
- Run the script
// Separate objects based on Face Selection
// Created by Denes Dankhazi
// Environment artist at Digic Pictures
{
// Get the objects name based on the face selections
string $selObj[] = `ls -hl`;
for ($item in $selObj)
{
// Select object
select $item;
// Get the number of all polygons in that object
int $numFce[] = `polyEvaluate -f`;
// Change the selection mode
changeSelectMode -component;
// Get the number of the selected polygons in that object
int $numFs[] = `polyEvaluate -fc`;
// Testing the number of polygons. All vs Selected
if ($numFce[0] != $numFs[0])
{
select $item;
// Duplicate the object with and modify the name. Fortunately Maya keeps the selection when an object is duplicated. :)
string $dupli[] = `duplicate -n ($item + "_separated")`;
doMenuComponentSelectionExt($dupli[0], "facet", 0);
InvertSelection;
//print `ls -sl`;
delete;
select $item;
doMenuComponentSelectionExt($item, "facet", 0);
//print `ls -sl`;
delete;
changeSelectMode -object;
}
else {print ("It's unnecessary to separate this object: \n" + $item + ".\nAll faces was selected.\n");}
}
changeSelectMode -object;
}
Cheers, D
Unfortunately, this method does not always work (sometimes Maya doesn’t keep the selection at the duplication process.) I will modify the script soon to compensate this.
Update 1: A modified version of the script. Fixed a few things. Still not perfect. 🙂
Thank you!!!!!
You are a God amongst men.