UV set copy and delete

UV set copy and delete

Anonymous
Not applicable
8,977 Views
5 Replies
Message 1 of 6

UV set copy and delete

Anonymous
Not applicable

I found this script:

{
string $selectedObjects[] = `ls -sl`;
int $selectionSize = `size($selectedObjects)`;

for ($i = $selectionSize; $i > 0; $i--){
    polyUVSet -currentUVSet -uvSet "uvSet" $selectedObjects;
    polyCopyUV -uvSetNameInput "" -uvSetName "map1"  -ch 1 $selectedObjects;
    polyUVSet -currentUVSet -uvSet "uvSet" $selectedObjects;
    polyUVSet -delete $selectedObjects;
//  DeleteHistory $selectedObjects;
    }
}

however maya gives an error: doesn't work on multiple objects selected. What am I doing wrong to run this script while multiple objects are selected? 

0 Likes
Accepted solutions (1)
8,978 Views
5 Replies
Replies (5)
Message 2 of 6

mspeer
Consultant
Consultant
Accepted solution

Hi!

 

There are many errors in this script. I recommend to use UV Editor and UV Set Editor for these type of operations, but anyway here is a corrected and cut-down version of the script:

 

{
string $selectedObjects[] = `ls -sl`;
int $selectionSize = `size($selectedObjects)`;

int $i;
for ($i = $selectionSize-1; $i >= 0; $i--){
    polyCopyUV -uvSetNameInput "uvSet" -uvSetName "map1"  -ch 1 $selectedObjects[$i];
    polyUVSet -delete -uvSet "uvSet" $selectedObjects[$i];
//  DeleteHistory $selectedObjects[$i];
    }
}

 

and a "better" version:

 

{
string $selectedObjects[] = `ls -sl`;

string $sObject;
for ($sObject in $selectedObjects){
    polyCopyUV -uvSetNameInput "uvSet" -uvSetName "map1" $sObject;
    polyUVSet -delete -uvSet "uvSet" $sObject;
//  DeleteHistory $sObject;
    }
}

Keep in mind that this works only with objects containing at least 2 UV Sets named "uvSet" and "map1".

Message 3 of 6

Anonymous
Not applicable

>>"and a "better" version:"<<

 

Thanks so much for this, very helpful with 100's of imported objects. 🙂

0 Likes
Message 4 of 6

Anonymous
Not applicable

do you have a version based on the uvset index? i need to delete all uvsets that are not the default one, while the namings are unknown

0 Likes
Message 5 of 6

mspeer
Consultant
Consultant

Hi!

// delete all UV Sets except default uv set for all selected objects
{
string $selectedObjects[] = `ls -sl`;
string $sObject;
    for ($sObject in $selectedObjects){
        int $uv_id[] = `polyUVSet -q -allUVSetsIndices $sObject`;
        for ($i in $uv_id) {
            if($i != 0) {
                string $cuvname = `getAttr ($sObject+".uvSet["+$i+"].uvSetName")`;
                polyUVSet -delete -uvSet $cuvname $sObject;
            }
        }
    }
}
Message 6 of 6

Anonymous
Not applicable

awsome...this comes in handy

0 Likes