PDA

View Full Version : playblast script - my first GUI, could use some help


gonzalimator
10-19-2009, 10:42 AM
I won't bother going into the details of how much pain I went through getting the script to this point. At the moment, the script works, but it throws up an error if I use the "OK" button. The scene playblasts, but when it finishes an error states that the file exists and that the playblast is aborted. Basically I don't know why the script tries to playblast the file twice when using the OK button.

This is what I want to happen:


Run the script and the current viewport playblasts with the same name as the maya file and in the same directory.
If the script finds that there is a playblast with the same name that already exists, then a window opens up saying so.
The window allows the user to add a suffix to the file name, or they can choose to overwrite the existing file.
The playblast command gets executed when the user presses the ENTER key while in the text box, or presses either button. Then the UI closes.
I've never made a UI before, so any comments on how I built mine would be greatly appreciated. Also, since I'm not a scripter I would appreciate any comments about a better flow for the script, or a more elegant solution. I honestly didn't know if I should have my playblast proc before the GUI or after and why it should or shouldn't be that way (at one point it was after the GUI).

Here's the code (I marked the OK button with a big comment) :


//
// mgPlayblast
//
// Playblast your scene's current length in the same directory
// as the scene file. Names the playblast with the same name
// as the file. If file name exists a window pops up with
// a file name suffix option.
//


global proc mgPlayblast(string $newName){

// clear any selected items
select -cl;

// get new suffix
$newSuff = `textFieldGrp -q -text txtFld1`;

// playblast the sceneCam camera at 640x360
playblast -format movie -percent 100 -wh 640 360 -f ($newName + "_" + $newSuff);
}

global proc mgPlayblastUI() {
// get current scene path and name
string $fullPath = `file -q -sceneName`;
string $nameTemp = `match ".*\\." $fullPath`; // path with "." at the end
string $name = `substitute "\\." $nameTemp ""`; // strip off "." from $nameTemp
string $makeAVI = "playblast -format movie -percent 100 -wh 640 360";
// check for existing file
if (`file -q -exists ($name + ".avi")`){
//check for existing window
string $winName = "mgPlayblastUI";
if (`window -exists $winName`){
deleteUI $winName;
}
// window layout begins
window -title "mgPlayblast | File exists!" -wh 200 90 -resizeToFitChildren true $winName;
columnLayout -columnAttach "both" 12 -columnWidth 260 ;
columnLayout -columnAttach left 4 -rowSpacing 4;
text -label "The file name exists." message1;
text -label "Please provide a suffix or select \"Overwrite\"." message2;
textFieldGrp -columnWidth 1 40 -columnWidth 2 140 -columnAlign 1 right -columnAlign 2 both -label "Suffix\:" -text "noComment" txtFld1;
textFieldGrp -e -changeCommand ("mgPlayblast \"" + $name + "\"\; deleteUI " + $winName + "\;") txtFld1;
setParent ..;
columnLayout -columnAttach left 4 -rowSpacing 8;
rowLayout -columnWidth2 115 115 -height 30 -nc 2 -columnAttach2 left right -columnAlign2 center center;
button -width 90 -bgc 1.00 0.75 0.75 -label "Overwrite" -command ("deleteUI " + $winName + "\; " + $makeAVI + " -forceOverwrite -f \"" + $name + "\"") overBtn1;
/////////////////////////////////////
// HERE'S THE OK BUTTON //
/////////////////////////////////////
button -width 90 -label "OK" -command ("mgPlayblast \"" + $name + "\"\; deleteUI " + $winName + "\;") okBtn1;
setParent ..;
setParent ..;
showWindow $winName;
// end window layout
}
else{
// playblast file if file name doesn't exist
playblast -format movie -percent 100 -wh 640 360 -f $name;
}
}





Future plans include error checking, various options (resolution, choose compression).


Thanks in advance.
Marcos

goleafsgo
10-19-2009, 02:07 PM
Your problem is the callback that you've set with the "-changeCommand" flag on the textFieldGrp. That is going to get called when you hit enter or when the field loses focus. eg. try typing something in the field and then tabbing out of it...it should try to create the file right away. So what I think is happening is when you start to press your ok button it first fires of the textFieldGrp callback and then the ok button callback.

gonzalimator
10-19-2009, 09:14 PM
Thanks for the reply Tim. I understand what's happening now. I wanted my proc to execute when someone presses Enter in the text field or presses OK. Is it impossible to do that in a MEL GUI?

CGTalk Moderation
10-19-2009, 09:14 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.