Maya MEL Scale UV shells locally script for anyone that wants it

vertex
Offline / Send Message
Sean_P vertex

NOTE: look to the bottom of the thread for updates on the script


I wanted to locally scale some UV shells and found that Maya didn't have the functionality so i wrote a script to do it.  I included a lot of info about the script so people can use it to learn about splitting an array, appending to an array, get min and max value from and array of floats and finding the pivot point of a shell(the bulk of the script).  A lot of this was hard to find or non existent on the net and I had to figure it out by myself.  Therefore I'm just putting this up so if people face similar issues it will only be a simple google search and not a day of heartache.

Now about the script itself.

Scaling shells:

All Maya can do by Default...(smacks head)


What my script does

Edit: firefox definitely doesn't like the code format.


The Script:

//select one uv point in each shell you would like to scale

//assign Shells into a list and determine how many selected string $uvshelllistt[] = `ls -sl -fl`; int $shellselSize = `size($uvshelllistt)`;

//a loop that goes through each shell one at a time //converts to a uvshell, finds the centre pivot point //and scales the mesh due to the input for($L = 0; $L < $shellselSize; $L++) { //selects uvpoint select -r $uvshelllistt[$L]; //convert shell to shell of uvpoints polySelectBorderShell 0; //create an array of all UV locations float $uvvalues[] =`polyEditUV -q`; //number of values in array of all locations, used for the looping int $selSize = `size ($uvvalues)`; //This next bit will split the array of both UV values into 2 //with only the u and v values in each array using every second //number starting from different points as the main procedure float $Uarray[]; float $Varray[]; //loop for U array starting from the first number for($u = 0; $u < $selSize; $u++) { $Uarray[size($Uarray)] = $uvvalues[$u]; $u=$u+1; } //loop for V array starting from the second number for($v = 1; $v < $selSize; $v++) { $Varray[size($Varray)] = $uvvalues[$v]; $v=$v+1; } //sort both arrays into acending order so first number will //be the lowest (min) U or V value and the last the highest (max) $Uarray = `sort $Uarray`; $Varray = `sort $Varray`; //only need to find the size of one array //they both have the same number of values //i use this to select the last number in the array int $UarraySize = `size ($Uarray)`;
//Max number in U array float $maxNuU = $Uarray[$UarraySize-1]; //Max number in V array float $maxNuV = $Varray[$UarraySize-1]; //Min number in U array float $minNuU = $Uarray[0]; //Min number in V array float $minNuV = $Varray[0]; //get the average of the range to define pivot float $middleU = ($maxNuU + $minNuU)/2; float $middleV = ($maxNuV + $minNuV)/2; //scale with the pivot we have defined polyEditUVShell -pu $middleU -pv $middleV -su .99 -sv .99; } //restore selection to user selected allowing you to re-run command select -r $uvshelllistt;

Replies

  • Add3r
    Offline / Send Message
    Add3r polycounter lvl 5
    Dope, something I had actually been looking at figuring out myself in my spare time.  This is something that has always bugged me with Maya's tools since I usually only pack my unwrapped models in its UV editor.  Thank you sir :) 
  • Sean_P
    Offline / Send Message
    Sean_P vertex
    I'm glad it helps, working with mel in the UV space isn't fun
  • Deadly Nightshade
    Offline / Send Message
    Deadly Nightshade polycounter lvl 4
    Congrats on your first(?) script! I know what you've gone through - I've been where you are myself: looking at the Maya UV editor and realize just how limited it is. Relative transforms on multi-shell selections is just one thing out of many that is missing.

    I disagree though that the information is hard to find. I would argue that it's much more about knowing where and how to find said information. In fact, the Maya commands documentation (as well as the PyMEL documentation) is really good. I doubt you've missed it but I'll post it here for others: http://help.autodesk.com/cloudhelp/2016/ENU/Maya-Tech-Docs/Commands/

    As for dealing with Maya programming problems, this forum has been of great aid to me over the years:
    http://forums.cgsociety.org/forumdisplay.php?f=89

    Feedback:
    -You are overcomplicating things by dividing things into two arrays. Instead you could use something like a matrix.
    -Avoid using the select command inside loops as it is "expensive" - especially when working on mesh components (vertices, UV's, etc). It's amazing how much you can reduce execution time by eradicating select from your code by using other commands (ls, polyListComponentConversion, polySelectConstraint and so on).
    -For more speed, code in PyMEL. You can learn Python here: http://www.codeacademy.com
    If you want to do more coding in Maya then my recommendation is to move away from MEL when you are more comfy with it. Most people think that MEL is a poor language.
    -For even more speed, create custom classes for points, lines, polygons and do computations with them, before manipulating "actual" components in the scene.
    -You can't present code like this with the horrible formatting of one quotebox per line of code - it's difficult to read :(

    Edit:
    If you want another coding challenge, try recreating one of the core features of my tool (Orient shells for example):


  • Sean_P
    Offline / Send Message
    Sean_P vertex
    Hey Deadly NIghtshade,

    Definitely first script in the UV space, i find the difference is night and day with the 3d space (querying a pivot point or even the fact that ordered selection doesn't work with uv points)

    I was looking for the local scaling functionality a couple of days ago and saw your script but every time i went onto creative crash there was a server error so i thought i could wait or figure it out myself.

    The commands themselves aren't hard to find but  information on finding the minimum and maximum value in an array (with MEL), didn't find anything on that.

    Cgsociety is definitely a great website and has been a help to me as well.

    100% agree python is the way to go in the future.

    I love the feedback, and i agree the formatting looks terrible, which i think has something to do with firefox.


    p.s. already have a script for that thanks to http://polycount.com/discussion/156560/scripting-beginnerhttp://



  • Sean_P
    Offline / Send Message
    Sean_P vertex
    I was able to shorten/cleanup up the script using the polyEvaluate -bc2 command

    Deadly Nightshade, I'm very intrigued about removing the select command to improve performance, but i haven't got the slightest idea on how

    //select one uv point in each shell you would like to scale

    //assign Shells into a list and determine how many selected
    string $uvshelllistt[] = `ls -sl -fl`;
    int $shellselSize = `size($uvshelllistt)`;

    //a loop that goes through each shell one at a time
    //converts to a uvshell, finds the centre pivot point
    //and scales the mesh due to the input
    for($L = 0; $L < $shellselSize; $L++) {
    //selects uvpoint
    select -r $uvshelllistt[$L];
    //convert shell to shell of uvpoints
    polySelectBorderShell 0;
    //finds out the uv coordinates of a bounding box in uvspace
    float $BC2var[] = `polyEvaluate -bc2 -ae`;
    //create pivot from bounding box coordinites
    float $middleU = ($BC2var[0] + $BC2var[1])/2;
    float $middleV = ($BC2var[2] + $BC2var[3])/2;
    //scale with the pivot we have defined
    polyEditUVShell -pu $middleU -pv $middleV -su .99 -sv .99;
    }
    //restore selection to user selected allowing you to re-run command

    select -r $uvshelllistt;

  • Flynny
    Offline / Send Message
    Flynny polycounter lvl 9
    I just remade this tool in python for an artist: 

    http://pastebin.com/fL6CCrzZ

    http://imgur.com/a/9fyLj


    Enjoy.
  • Sean_P
    Offline / Send Message
    Sean_P vertex
     Flynny said:
    I just remade this tool in python for an artist: 

    http://pastebin.com/fL6CCrzZ

    http://imgur.com/a/9fyLj


    Enjoy.

    I like how you used face selection, probably a bit faster than selecting the UV vert

    I hope this thread helped in the development of the tool :)

  • Sean_P
    Offline / Send Message
    Sean_P vertex

    After seeing Flynny use face selection I have modified my script to take any input, face, edge, vert, uv.  However uvshell is not supported (maya why?).

    So basically you can select one face or edge or vert or uv point in each shell you want to scale and it will work.

    important if you select more than 1 in each shell it will cause the script to scale that shell twice


    //select one uv point in each shell you would like to scale

    //assign Shells into a list and determine how many selected
    string $uvshelllistt[] = `ls -sl -fl`;
    int $shellselSize = `size($uvshelllistt)`;


    //a loop that goes through each shell one at a time
    //converts to a uvshell, finds the centre pivot point
    //and scales the mesh due to the input
    for($L = 0; $L < $shellselSize; $L++) { 
    //selects uvpoint
    select -r $uvshelllistt[$L];

    //convert whatever type of selection (face, edge, vert, uv) to uv
    textureWindowSelectConvert 4;

    //convert shell to shell of uvpoints
    polySelectBorderShell 0;

    float $BC2var[] = `polyEvaluate -bc2`;
    float $middleU = ($BC2var[0] + $BC2var[1])/2;
    float $middleV = ($BC2var[2] + $BC2var[3])/2;


    //scale with the pivot we have defined
    polyEditUVShell -pu $middleU -pv $middleV -su .99 -sv .99;
    }
    //restore selection to user selected allowing you to re-run command


    select -r $uvshelllistt;



  • Sean_P
    Offline / Send Message
    Sean_P vertex
    Have gone through and made some improvements
    basically now there is a progress bar in the main window (bottom left corner)
    you can cancel the script with the escape key
    if you use edge selection you remain in edge selection mode and so on for the other selection modes

    //select one uv point,face,vert or edge in each shell you would like to scale
    //if you select more than one in each shell it will run the script twice for that shell
    //assign Shells into a list and determine how many selected
    string $uvshelllistt[] = `ls -sl -fl`;
    int $shellselSize = `size($uvshelllistt)`;

    //uses the progress bar in the main window
    progressBar -edit -beginProgress -isInterruptable true -status "Processing ..." -maxValue $shellselSize $gMainProgressBar;

    //a loop that goes through each shell one at a time
    //converts to a uvshell, finds the centre pivot point
    //and scales the mesh due to the input
    for($L = 0; $L < $shellselSize; $L++) { 
    //allows you to cancel during the running of the script
        if(`progressBar -query -isCancelled $gMainProgressBar`)
            break;
    //proceeds one step out of however many selections you made giving you a percentage
    progressBar -edit -step 1 $gMainProgressBar;

    //selects uvpoint
    select -r $uvshelllistt[$L];

    //convert whatever type of selection (face, edge, vert, uv) to uv
    textureWindowSelectConvert 4;

    //convert shell to shell of uvpoints
    polySelectBorderShell 0;

    float $BC2var[] = `polyEvaluate -bc2`;
    float $middleU = ($BC2var[0] + $BC2var[1])/2;
    float $middleV = ($BC2var[2] + $BC2var[3])/2;

    //scale with the pivot we have defined
    polyEditUVShell -pu $middleU -pv $middleV -su .99 -sv .99;
    }

    //closes progress bar after loop is complete
    progressBar -edit
        -endProgress
        $gMainProgressBar;
    //used the list selection to determine what selection mode you used and converts yo back to it after using uv points
    if (`gmatch $uvshelllistt[0] "*.vtx*"`)
    PolySelectConvert 3;
    if (`gmatch $uvshelllistt[0] "*.e*"`)
    PolySelectConvert 2;
    if (`gmatch $uvshelllistt[0] "*.f*"`)
    PolySelectConvert 10;

    //restore selection to user selected allowing you to re-run command
    select -r $uvshelllistt;

  • Sean_P
    Offline / Send Message
    Sean_P vertex
    I've updated this tool
    now you can use a slider to scale, you can scale down or back up to original, it remembers the original scale



    //Global variable declaration
    global string $gMainProgressBar;
    global string $uvshelllistt2[]; global float $equasionout = 1; global float $scaleamount = 1;
    //Window commands $window = `window -h 30 -w 50 -t "Local Scale" -s off -tlc 200 500`; rowColumnLayout -cw 10 10; text -l ""; text -l "Local Scale Tool"; text -l ""; floatSliderGrp -cc "changenumber" -ss 0.01 -cw3 40 40 150 -v 1 -minValue 0.1 -maxValue 1.000 -label "Scale" -field true slider1; showWindow;
    //procedure driven by slider proc changenumber() { //Global variable declaration global string $gMainProgressBar; global float $scaleamount; global float $equasionout; global string $uvshelllistt2[]; //assign Shells into a list and determine how many selected string $uvshelllistt[] = `ls -sl -fl`; int $shellselSize = `size($uvshelllistt)`; //this check to see if the selection has changed and //if so will reset the scale back to 1 if ($uvshelllistt[0]!=$uvshelllistt2[0]){ $scaleamount = 1; } $uvshelllistt2 = $uvshelllistt; //Variables that use some simple math to scale and keep track of scale float $inputnum1 = `floatSliderGrp -q -value slider1`; float $equasionout = $inputnum1/$scaleamount; float $scaleamount = $scaleamount*$equasionout; //uses the progress bar in the main window progressBar -edit -beginProgress -isInterruptable true -status "Processing ..." -maxValue $shellselSize $gMainProgressBar; //a loop that goes through each shell one at a time //converts to a uvshell, finds the centre pivot point //and scales the mesh due to the input for($L = 0; $L < $shellselSize; $L++) { //allows you to cancel during the running of the script if(`progressBar -query -isCancelled $gMainProgressBar`) break; //proceeds one step every loop out of however many selections you made (progress bar) progressBar -edit -step 1 $gMainProgressBar; //selects uvpoint select -r $uvshelllistt[$L]; //convert whatever type of selection (face, edge, vert, uv) to uv textureWindowSelectConvert 4; //convert uv point to shell of uvpoints polySelectBorderShell 0; //Calculates centre of shell (pivot) float $BC2var[] = `polyEvaluate -bc2`; float $middleU = ($BC2var[0] + $BC2var[1])/2; float $middleV = ($BC2var[2] + $BC2var[3])/2; //scale using the pivot and the scale we have defined polyEditUVShell -pu $middleU -pv $middleV -su $equasionout -sv $equasionout; } //at 100% completion close progress bar progressBar -edit -endProgress $gMainProgressBar;
    //checking to see what selection mode you used and restoring selection mode if (`gmatch $uvshelllistt[0] "*.vtx*"`) PolySelectConvert 3; if (`gmatch $uvshelllistt[0] "*.e*"`) PolySelectConvert 2; if (`gmatch $uvshelllistt[0] "*.f*"`) PolySelectConvert 10; //restore selection to user selected and allowing you to re-run command select -r $uvshelllistt; }
  • Maddog4america
    Is there a way to drag and select all the uv shells instead of selecting one point from the shell?  When selecting all the points it scales weird.   It would be nice if you could scale all of them really quickly from a drag select all
  • oglu
    Online / Send Message
    oglu polycounter lvl 8
    Is there a way to drag and select all the uv shells instead of selecting one point from the shell?  When selecting all the points it scales weird.   It would be nice if you could scale all of them really quickly from a drag select all
    YES please
Sign In or Register to comment.