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
}

No comments:

Post a Comment