Showing posts with label Mel. Show all posts
Showing posts with label Mel. Show all posts

08 July 2011

Mel Scripting - Moving UVs

Here's a script I thought of when I was trying to match the UVs of 2 different objects. If you use the Smooth UV tool and are anal about your UVs then this may come in handy however most people don't even care if 2 walls have slightly off brick textures!

This script has the ability to move and scale UVs.

if (`window -exists MovingUVs`)
deleteUI MovingUVs;

textureWindowSelectConvert 4; //making sure we select UVs of the object

window -width 20 -height 20 "MovingUVs";

gridLayout
-numberOfRowsColumns 1 3
-cellWidthHeight 75 20;

text -l " "; //blank space
button -label "Up" -c "GoingUp();";
text -l " ";
button -label "Left" -c "GoingLeft();";
text -l " ";
button -label "Right" -c "GoingRight();";
text -l " ";
button -label "Down" -c "GoingDown();";
text -l " ";
button -label "Scale+" -c "ScaleUp();";
text -l " ";
text -l " ";
button -label "Scale-" -c "ScaleDown();";

setParent ..;

showWindow MovingUVs;

      //edit these values if you it to have a greater effect
global proc GoingUp()
{
       polyEditUV -u 0 -v 0.001;
}
global proc GoingDown()
{
       polyEditUV -u 0 -v -0.001;
}
global proc GoingLeft()
{
       polyEditUV -u -0.001 -v -0;
}
global proc GoingRight()
{
       polyEditUV -u 0.001 -v -0;
}
global proc ScaleUp()
{
       polyEditUV -su 1.001 -sv 1.001 ;
}
global proc ScaleDown()
{
       polyEditUV -su 0.999 -sv 0.999 ;
};

14 March 2011

Mel scripting - toggle move tool axis

Just made a little script to go through the most useful (to me) move tool axis settings aka World, Object and Normal. I've also added a fancy little message box to tell you what you've selected, not really necessary but cool nonetheless!


int $MoveAxis = `manipMoveContext -q -mode Move`;

if ($MoveAxis == 0)
{
manipMoveContext -e -mode 2 Move;

$response = `confirmDialog -title "Axis"
-message "World move axis has been set!"
-button "OK"`;
}
else if ($MoveAxis == 2)
{
manipMoveContext -e -mode 3 Move;

$response = `confirmDialog -title "Axis"
-message "Normal move axis has been set - remember to select vertices!"
-button "OK"`;

}
else if ($MoveAxis == 3)
{
manipMoveContext -e -mode 0 Move;

$response = `confirmDialog -title "Axis"
-message "Object move axis has been set!"
-button "OK"`;

}

15 February 2011

Mel scripting - open image with Photoshop!

Alright so here's a Mel script I've been working on for the last 24 hours - it took longer than expected!

The main point of this was... I'm lazy :D I wanted to open up the UV Snaphot I just made and I didn't want to open up Windows Explorer and find the image. Instead I wanted to open the image straight from Maya into Photoshop. With Maya 2011's new user interface, you can easily select a sub-folder of the project you're currently working on so this script only benefits Maya 2011 users.

This is my first attempt at UI in Mel and probably the most difficult script I've attempted to far..


if (`window -ex OpenImage`) deleteUI OpenImage; //closes if it's already running

//window
window -wh 300 60 "OpenImage";
columnLayout -columnWidth 300;
rowLayout -columnWidth2 10 60 -numberOfColumns 2;
button -width 90 -label "Select Image..." -c "fileBrowser(\"FileLoc\",\"Open\",\"\",0)";
textField -width 200 FileLocation;
setParent -u;
columnLayout -columnWidth 300;
button -width 292 -label "Launch in Photoshop!" -c "loadPhotoshop();"; //run procedure
showWindow OpenImage; //launches window
//window end

//edits the textbox with the filename selected
global proc FileLoc(string $filename, string $type)
{
textField -e -tx $filename FileLocation;
}

//procedure
global proc loadPhotoshop()
{
//photoshop location - REMEMBER TO CHANGE THIS TO YOUR PHOTOSHOP LOCATION
     string $PhotoshopL = "C:/Program Files (x86)/Adobe/Adobe Photoshop CS3/photoshop.exe"; 
        //photoshop location - REMEMBER TO CHANGE THIS TO YOUR PHOTOSHOP LOCATION
    
     string $FileL = toNativePath(`textField -q -tx FileLocation`); //converts the windows path (\) to Maya paths (/)
     system("start \""+$PhotoshopL+"\" \""+$FileL+"\""); //adds both the photoshop path and file path and launches it via the system 
     deleteUI OpenImage; //closes the UI
}

28 January 2011

Mel scripting - toggle Pin UV Borders

Pretty similar to the other script I made a few posts down.

This is for the Smooth UV Tool in the UV Texture Editor. I find it quite tedious to keep opening up the tool to toggle the Pin Borders option so I thought this would shave off a few seconds!

I also made sure that when the Pin Borders is toggled off, it will automatically select the current object's shell so you can get on with the smoothing :D


//finding out what the value is set to
int $smoothResult = `texSmoothContext -q -pb texSmoothCtx`;


if ($smoothResult == 0)
    {   
//toggle on 
        texSmoothContext -e -pb true texSmoothCtx;
        print ("Pin borders: ON\n");
    }
    else
        {
   //toggle off
            texSmoothContext -e -pb false texSmoothCtx;
   //selects the shell of the selected object so you can smooth those UVs asap!
            polySelectBorderShell 0;
            print ("Pin borders: OFF\n");
        }
    
  

24 January 2011

Mel scripting - toggle Snap Component Spacing

Hello world!

So right, I decided to start a new project today and create some little props to get me back into the whole workflow. I then thought of a little script to toggle on/off the snap component spacing - it's annoying to keep going into the Move tool settings!

So here you have it:

//here we're finding out what the current value of the snap component is (0 = false and 1 = true)
int $snapResult = `manipMoveContext -q -snapComponentsRelative Move`;


//run this batch of code if the value is false (0)
if ($snapResult == 0)
    {
         //setting the component spacing to true
         manipMoveContext -e -snapComponentsRelative true Move;
         print ("Component spacing: ON\n");
    }
         //run this batch of code if the value is anything other than 0, in this case - 1
         else
             {
                  manipMoveContext -e -snapComponentsRelative false Move;
                  print ("Component spacing: OFF\n");
              }


We could have done this much easier by using the "Double Click" option in the Shelf editor but where's the fun in that? :P