(MEL) problem with reordering uvset script

(MEL) problem with reordering uvset script

absoluteKelvin
Collaborator Collaborator
481 Views
3 Replies
Message 1 of 4

(MEL) problem with reordering uvset script

absoluteKelvin
Collaborator
Collaborator

 

{
   string $mesh[] = `ls -sl`;
   string $uvSets[] = `polyUVSet -q -allUVSets`;
   int $setNum[];
   //int $counter = 0;
   for ($i = 0; $i < size($uvSets); $i++){
       $setNum[$i] = int(`match "[0-9]+$" $uvSets[$i]`); //extract uvSet number
       if ($setNum[$i] != ($i + 1)) // if there is mismatch then run the following
       {
           int $nuvSetNum = $setNum[$i] - 1;
           //print $nuvSetNum;
           polyUVSet -reorder -uvSet $uvSets[$i] -nuv $uvSets[$nuvSetNum]; //swap uvSets
           $uvSet[$i] = $uvSets[$nuvSetNum]; //update the uvSet array
           updateUvSetEditor;
       }
   }
}

 

 

this script is making the assumption that the uvSets are name with the same prefix (ie map1 map2 map3...)

 

what it is suppose to do is reorder the uvSets to numerical order.

example

 

map2

map3

map5

map1

map4

 

would become

 

map1

map2

map3

map4

map5

 

not sure where it went wrong in the script. any help is welcomed

https://www.artstation.com/kelvintam
0 Likes
482 Views
3 Replies
Replies (3)
Message 2 of 4

mcw0
Advisor
Advisor

Don't know about the rest of the code.  But this is what I saw on initial inspection.

 

Shouldn't this 

$uvSet[$i] = $uvSets[$nuvSetNum]; //update the uvSet array

be

$uvSets[$i] = $uvSets[$nuvSetNum]; //update the uvSet array

 

0 Likes
Message 3 of 4

absoluteKelvin
Collaborator
Collaborator

great catch mcw0. Now it works some times. but most of the time i run into this error

 

Error: line 13: Cannot reorder same uv sets. No reorder performed.

https://www.artstation.com/kelvintam
0 Likes
Message 4 of 4

absoluteKelvin
Collaborator
Collaborator

interestingly after looking at the code in uvTkBuildUVSetsOptions.mel. I was able to get it to work somehow but not the way i want it to. the uvs get sorted after i run the code a few times.

 

{
   string $mesh[] = `ls -sl`;
   string $uvSets[] = `polyUVSet -q -allUVSets`;
   int $setNum[];
   //int $counter = 0;
   for ($i = 0; $i < size($uvSets); $i++){
       //$setNum[size($setNum)] = int(`match "[0-9]+" $set`)
       $setNum[$i] = int(`match "[0-9]+$" $uvSets[$i]`);
       if ($setNum[$i] != ($i + 1))
       {
           int $destIndex = $i - 1;
           while ($destIndex >= 0)
           {
               polyUVSet -reorder -uvSet $uvSets[$i] -nuv $uvSets[$destIndex];
               $destIndex-- ;
           }
       updateUvSetEditor;    
       //$uvSets = `textScrollList -q -allItems uvSetList`;
       }
   }
}

 

https://www.artstation.com/kelvintam
0 Likes