
I think it's time to go through the script now. You probably
have enough knowlege to attack scripts now.
Remember that even if something here is not too clear right
now you'll learn from experience. Remember
how I told you I couldn't get my head around loops? I wasn't
kidding when I said it took weeks. Even when
someone explained them to me I just couldn't. Stupid, stupid,
stupid... Then I started using them and
I felt more comfortable with them right away. You will learn
faster by doing. Everyone knows this! Do it!
Ok, what I want the script to do is this:
- List the objects I want to edit. I want to be able to
select just some of the objects from the list too.
I also want to be able to change the selection without
reopening the window.
- I want a layout with checkboxes for the renderStats.
- I want a button that cycles through all the choices
I made with the checkBoxes and applies the new
renderSettings.
When I picture this script in my head it looks like this:
( quick paintover... )

I'm also writing down which commands I think I'll end up
using. Programmers have their own way of scripting.
Someone likes to do all the code first and make that work
before they even think about the UI, others
script the UI first and then worry about the core. I am
a 3d artist and not a programmer so I tend to care more
about how thing looks, maybe a bit too much really :) But
anyways, with this script I'll go from top to bottom:
window: You should ask yourself: "Does the script
really need a UI?" If you don't rely on user interaction
there
is no need for a UI. It could be a shelfButton instead.
In this case we actually need an interface. I'll also make
sure Maya deletes my window if it exists, just like we did
earlier.
if(`window -ex ma_multiAttrEdWin`)deleteUI
ma_multiAttrEdWin;
window -t "final3 Multiple renderStatsEditor"
-wh 280 294 ma_multiAttrEdWin;
showWindow ma_multiAttrEdWin;
You might noticed that the deleteUI-command is on the same
line as the if statement and I also left the
curly braces out. When you only have ONE line to go between
the curly braces you can skip them. For
beginners I reccomend you stick with the curly braces so
you won't forget them later. Stick with this code for
a while:
if(`window -ex ma_multiAttrEdWin`){
deleteUI ma_multiAttrEdWin;
}
I gave the window a title, defined the width and heigt
using the -wh flag and I also gave the window an ID. But
in Maya you will always need some sort of layout to hold
anything at all. If you try to put a button in there
between the window and showWindow command you'll get this
error :
// Error: line 4: Controls must have a layout. No layout
found in window : ma_multiAttrEdWin //
If you hit f1 you can read more about Maya's UI controls.
Under Developer resources -> Mel commands you'll
se them listed on the far right:
I'd say the most common layout is columnLayout. If we look
at the sketch I drew we see that I need more
than one column, I need two ( one for the textScrollList
and one for the checkBoxes. I still have to use
a columnLayout to hold it all together though so I create
a columnLayout first and then the rowColumnLayout.
In a rowColumnLayout you can define how many columns you
want per row:
window -t "final3 Multiple renderStatsEditor"
-wh 280 294 ma_multiAttrEdWin;
columnLayout;
rowColumnLayout -nc 2 -cw 1 152 -cw 2 120;
showWindow ma_multiAttrEdWin;
What the flag -cw does is define the width for the columns.
The width for column 1 should be 152 and the
width for column 2 should be 120. These are numbers I have
found best for this exact script. You need to
try out many values here and there before you find something
that fits. When you create a window like this
you'll have to nest several layouts and controls. There
are different ways of achieving the same looks so
basicly do it the way you feel like doing it as long as
it works. This is how I set up the layouts for my window:
window -t "final3 Multiple renderStatsEditor"
-wh 285 295 ma_multiAttrEdWin;
columnLayout;
rowColumnLayout -nc 2 -cw 1 154 -cw 2 122 -h 230;
frameLayout -l "objects:" -fn "smallFixedWidthFont"
-bs "etchedIn" -h 232;
columnLayout;
textScrollList -w 150 -h 190 -ams 1 ma_multiAttrEdTSL;
button -l "update selection" -w 148;
setParent..;
setParent..;
frameLayout -l "options:" -fn "smallFixedWidthFont"
-bs "etchedIn" -h 200;
columnLayout ma_optionsColumn;
showWindow ma_multiAttrEdWin;
If you execute this code you get this:

You can see how the rowColumnLayout sets the different
width for the two framelayouts, I have labels for
both my frameLayouts and I also have the controls textScrollList
(empty white list) and a button. The reason
I haven't put in the controls for the options-side yet is
because I plan to do this in a very different way. You
can also see that I put in a new command called setParent..;
What this command does it to guide us out of
the current layout and one step upwards. See this paintover:

- The green layout is the main columnLayout. This is the
first layout we put ourselves in.
- Then we create the rowColumnLayout. Now we are inside
this one and this layout is also inside the green
one
- Then we create a frameLayout. This layout is inside
the rowColumnLayout that is inside the green one.
This frameLayout represents the first column in the rowColumnLayout.
- The layouts are defined and we create a columnLayout
to hold the controls. This layout is then inside
the frameLayout. So far we have gone like this:
columnLayout-->rowColumnLayout-->frameLayout-->columnLayout...
So when we go back once (setParent..;) we go back to frameLayout.
Then the second setParent will guide
us back to the layout above this one again which is rowColumnLayout.
Now we are ready to define the
second column. So after the second setParent we simply
write frameLayout because that's the layout
we want for the optionsColumn. It would have been easier
to see this if we named the layouts, but I
only name the ones I know I'll be modifying later.
|