|
Ok, now that we have the basic layout we can start fixing the parts one by one. I will start with the
textScrollList. I want this control to list selected objects. Now, we have already talked about the command we have to use here "ls". But how are we going to get this command to throw values into the textScrollList. We create a proc for this, see code below (I had to put the code in a table to make it more readable. If you wish to copy the code, use the code with a white background below.):
global proc ma_multiAttrEdList ()
{
string $ma_selected[] = `ls -sl`;
if (!(`size($ma_selected)`))
{
warning "nothing selected. List will not display any objects";
}
else
{
textScrollList -e -ra ma_multiAttrEdTSL;
for ($ma_sel in $ma_selected)
{
string $ma_pickWalked[] = `pickWalk -d down $ma_sel`;
textScrollList -e -a $ma_pickWalked ma_multiAttrEdTSL;
}
}
}
Now this proc has a lot of actions, it includes an "if statement" and a "for in loop". So now we get to see how this really works. I'm also going to explain the commands.
That's basically all the proc does. Now I'm going to do two things with this proc. First I'm going to put it in the command for the button and then I'll put it somewhere in the code between "window" and "showWindow". This way the list will be updated if the user has a selection when he/she opens the window. The changes are in bold letters:
if(`window -ex ma_multiAttrEdWin`)deleteUI ma_multiAttrEdWin;
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 -c ma_multiAttrEdList;
setParent..;
setParent..;
frameLayout -l "options:" -fn "smallFixedWidthFont" -bs "etchedIn" -h 200;
columnLayout ma_optionsColumn;
ma_multiAttrEdList;
showWindow ma_multiAttrEdWin;
You can try it out. If you click the button after selecting some objects the list gets updated. Funny stuff huh? :)
Now the tricky part begins. I want to build the checkboxes and I also want to create a button that changes the renderStats... Well, you might think. That shouldn't be a problem. You can just add a lot of checkBoxes and create integers that check the values and then you can just let the button go through all that?
Well, I don't want to use a lot of lines for this and I also want it to be easy to remove or add checkBoxes. Therefore I create an array that holds all the info I need to create the checkBoxes and the command for the button. Then there's some mixin' and trixin' to nest all this together. I'll write down the code and go through it step by step.
//Array that defines the commands I want to use
global string $ma_meshArray[] = {"castsShadows" , "receiveShadows" , "motionBlur", "primaryVisibility" ,
"smoothShading" , "visibleInReflections" , "visibleInRefractions" , "doubleSided" , "opposite"};
I know which attributes the renderStats hold so I simply create an array that can store all of these. Now I can use these as labels as well as commands. ( Because I do it like this the labels will not have the EXACT same name as in the attributeEditor.) The way I found out which strings to write down was simple. I turn "echo all commands" on in the scriptEditor, select an object, open the attributeEditor and check/uncheck stats. Then I can read directly in the scriptEditor what Maya changes. Notice that I declared the array as a GLOBAL string. This is because I want to use it later inside another loop and if I want to use strings like that I have to make them global.
//A loop building all the "options" - UI
for ($i = 0; $i < `size($ma_meshArray)`; $i++)
{
checkBox -l $ma_meshArray[$i] -v 1 -p ma_optionsColumn ($ma_meshArray[$i] + "checkBox");
}
You should be able to read this now. This is very close to the example I used earlier, only the command here is different. The loop checks the size of the array ( which is 9 (count the strings in the array above) ) Let's say we go through the loop with the first string in the array as an example "castsShadow".
checkBox -l "castsShadow" -v 1 -p optionsColumn castsShadowcheckBox;
Notice that there is a flag here "-p" that parents this checkBox to the optionsColumn. This column was empty earlier. Now it's time to fill it. We'll fill it the way we filled a window with 50 buttons in the loop example.
If you look at the sketch again you see that I also want a button here. So right after the loop I add these lines: ( I decided to put a separator there too...)
separator -h 46 -w 115;
button -w 116 -l "Edit RenderStats";
Now we already have a UI where the button on the left can update our list and we also have a lot of check boxes here :) Pluss a separator and a button ( A button that doesn't do anything yet... )
Let's see if the checkBox loop works. This is how it looks so far:
|