View Full Version : UI code wrong ?
10-12-2010, 03:14 PM
Hi, I can't seem to get this to behave properly, the window always seems to be a random size, not the width height I have set ?
if(`window -ex $vcsWindow`) deleteUI $vcsWindow ;
string $vcsWindow = `window -s 0 -title "Blah Blah" -widthHeight 200 440` ;
string $vcsForm = `formLayout -numberOfDivisions 100` ;
string $vcsFButton01 = `button -h 22 -w 200 -label "Blah Blah" -command ""`;
string $vcsFButton02 = `button -h 22 -w 200 -label "Blah Blah" -command ""`;
string $vcsFButton03 = `button -h 22 -w 200 -label "Blah Blah" -command ""`;
string $vcsFButton04 = `button -h 22 -w 200 -label "Blah Blah" -command ""`;
string $vcsFButton05 = `button -h 22 -w 200 -bgc 0.953 0.565 0.482 -label "Blah Blah" -command ""`;
-attachForm $vcsFButton01 "top" 0
-attachForm $vcsFButton01 "left" 0
-attachForm $vcsFButton02 "top" 22
-attachForm $vcsFButton02 "left" 0
-attachForm $vcsFButton03 "top" 44
-attachForm $vcsFButton03 "left" 0
-attachForm $vcsFButton04 "top" 66
-attachForm $vcsFButton04 "left" 0
-attachForm $vcsFButton05 "top" 88
-attachForm $vcsFButton05 "left" 0
10-12-2010, 04:03 PM
This code is guarenteed to not work completely right first time, as you reference the variable $vcsWindow in the first line before you create it. It will have only worked before because you'd entered it in the script editor and globally defined it. if you restart Maya and run this code it will fail.
Anyway, Maya saves the sizes and positions of all windows you create so that it can restore them next time they appear. because you haven't given a name, Maya will choose something obvious like "window1" which you will have created hundreds of times before, so you will never be able to predict the size.
you can remove existing window prefs using the windowPref -remove command (although you need to pass in a specific window name) or you could just -edit the size just before you showWindow.
I find it very useful to hard-code my UI window names as it makes it easier to modify them sometime in the future or when they are active. This is how I make all my windows while I am writing a new one:
string $win = "toolNameWindow";
if (`window-q -ex $win`) deleteUI $win;
if (`windowPref -q -ex $win`) windowPref -remove $win;
window -wh 200 360 -tlb 1 -t "tool name" $win;
once the code is finished, or I have gotten the final size of my window nailed down, I simply delete (or comment out) the blue line.
10-12-2010, 04:29 PM
Thanks, again, Nathan ! lifesaver... :thumbsup:
10-13-2010, 12:36 PM
Never mind, fixed... :)
10-13-2010, 12:36 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.