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
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):
https://www.youtube.com/watch?v=mDOP6d-Fkdw
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://
Deadly Nightshade, I'm very intrigued about removing the select command to improve performance, but i haven't got the slightest idea on how
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
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
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
now you can use a slider to scale, you can scale down or back up to original, it remembers the original scale
</code><br><br><img title="Image: https://us.v-cdn.net/5021068/uploads/editor/fc/3ii3htscacmj.gif" src="https://us.v-cdn.net/5021068/uploads/editor/fc/3ii3htscacmj.gif" alt=""><br><br><pre class="CodeBlock"><code><code><code>//Global variable declaration