Project 10.3: The addition of a scrollLayout.


It is easy to add a UI that controls the execution of a script that has been created previously, or has no UI created by the original programmer. Moreover, with more complex tools, the task of creating the UI can be done by one scripter while another handles the actual operational portion of the tool. In this project, we will add a user interface to the generateGrass script from Chapter 6, "Geometry."

Design

Our goal will be to create a user interface that gives control of all the aspects of the script, is consistent with the Maya interface, and preferably makes the tool more intuitive to work with. After some thought and sketching, we can come up with a design we like, such as that in Figure 10.40.

click to expand
Figure 10.40: The Grass Generator UI design.

Once a design is approved, we can move on to the breakdown process. We need to identify each layout and control we will need to construct the UI. We know that the form layout gives us the most control, so we will use that as the root layout, seen in Figure 10.41.

click to expand
Figure 10.41: Breaking down the window to the formLayout.

Within that form layout, we will place a column layout to hold the majority of our controls. We will put the buttons directly in the form layout, for a reason we will discuss later. In Figure 10.42, we see the diagram of this third layer of layouts and controls.

click to expand
Figure 10.42: Inserting a columnLayout.

To keep the labels and controls properly aligned, we will place the controls in row layouts. Each of the labels will be created with text controls, and all of the controls will be created without labels. In Figure 10.43, we see a mapping of the finished UI, including which controls will be in which layout cell .

click to expand
Figure 10.43: The finished UI mapping.

Implementation

Adding UI windows should be done with a separate procedure than that which creates the actual functionality of the script. While developing the window, it is often preferable to keep this procedure in an entirely separate file, to allow for easy sourcing and execution, and to avoid accidentally causing errors in the functional script. Even after the UI is finished, it is not necessary to put all the procedures in one file, to keep both the command line and window interactions available to the end user.

Create and validate a script and procedure entitled grassUI . Our first goal is to create the window itself. To make the process of getting the dimensions of the labels and controls right and easy to change, we will use simple integer variables to hold assigned values, letting us quickly change them without searching through large volumes of text. In Example 10.44 we see the initial window definition, with two conditional statements used. The first is temporary, used to delete the UI if it exists, and used only during the construction of the UI.

Example 10.44: Validation of the script.

 global proc grassUI ()     {  // for use during building  if(`window -exists grassUI` != 1)         deleteUI grassUI;     if(`window -exists grassUI` != 1)         {         int $uiLabelWidth = 140;         int $uiInputWidth = 240;         int $uiWidth = ($uiLabelWidth + $uiInputWidth);         window             -maximizeButton false             -resizeToFitChildren false             -title "Grass Generator"             -iconName "Grass Generator"             -menuBar false             -wh 600 500             grassUI;         showWindow grassUI;         }     } 
On the CD  

The text for this script is found on the companion CD-ROM as Chapter_10/project_UI03/v01/grassUI.mel.

We can now execute this code, getting a result similar to Figure 10.44, although the relative size of the window is dependent on your desktop resolution and your operating system. We make the window inordinately large so we don t obscure any of our controls. Later, we will resize it to make it a much more reasonable size .

click to expand
Figure 10.44: The window in which we will build.

Next, we insert the form and column layouts, capturing the names to variables. The code in Example 10.45 is placed after the window creation, but still within the if statement.

Example 10.45: Addition of the basic layout elements.

 string $grassGenForm = `formLayout                                 -numberOfDivisions 100`;     string $grassColumn = `columnLayout                             -adjustableColumn true                             -rowSpacing 5`; 

Executing this code produces no visible differences. However, because we put the deleteUI statement within for testing, we are assured that the window is deleted and redrawn. This is essential when building a UI.

Next, we put in the control for selecting the style of grass and level of detail. First, we create a row layout with four columns . We then place our controls, seen in Example 10.46. Note the use of the variable in the definition of the layout.

Example 10.46: The first controls are added.

 rowLayout         -numberOfColumns 4         -columnAttach 1 "right" 5         -columnAttach 2 "both" 5         -columnAttach 3 "right" 5         -columnAttach 4 "both" 5         -columnWidth 1 $uiLabelWidth         -columnWidth 3 $uiLabelWidth         ;         text             -label "Grass Style"             -annotation                 "Select Grass Style.";         optionMenu             -label ""             grassGenStyleDropdown;                          menuItem -label "Short";             menuItem -label "Normal";             menuItem -label "Long";             menuItem -label "Very Long";         text             -label "Detail"             -annotation                 "Select Amount of Detail.";         optionMenu             -label ""             grassGenDetailDropdown;                          menuItem -label "Low";             menuItem -label "Medium";             menuItem -label "High";         setParent ..;  // Return to column layout  
On the CD  

The text for this script is found on the companion CD-ROM as Chapter_10/project_UI03/v02/grassUI.mel.

Using the annotation flags add what are more commonly known as "tool tips," giving quick instructions to the user. If we execute the script at this point, we get a result similar to Figure 10.45.

click to expand
Figure 10.45: Adding the Grass Style and Detail pull- downs .

Next, we add the slider, again by adding a Row Layout. This time, however, we will use three columns, to put the percentage label at the end. Since the desired layout conforms with that provided by the Float Slider Group, we will use it, rather than constructing it from components . This is shown in Example 10.47.

Example 10.47: Adding sliders, with separate text controls for labels.

 rowLayout         -numberOfColumns 3         -columnAttach 1 "right" 5         -columnWidth 1 $uiLabelWidth         -columnWidth 2 $uiInputWidth         grassDensityRow;                  text             -label "Density"             -annotation                 "Set the density parameter for the grass.";         floatSliderGrp             -field true             -minValue 0             -maxValue 100             -value 100             grassGenDensity;         text -label "0% - 100%";         setParent ..;  // Return to column layout  
On the CD  

The text for this script is found on the companion CD-ROM as Chapter_10/project_UI03/v03/grassUI.mel.

We again use the variables in the row layout definition, this time using both variables. Using this code results in the window seen in Figure 10.46.

click to expand
Figure 10.46: Adding the Density slider.

The fields for the minimum and maximum dimensions will be float fields. Again, this will require three column row layouts. To have the two fields together be the same width as the slider above, we will set each of the non-label columns to be half the width of the slider, conveniently defined with our variable. Example 10.48 shows this code.

Example 10.48: Float fields used to define our dimensions.

 rowLayout         -numberOfColumns 3         -columnAttach 1 "right" 5         -columnWidth 1 $uiLabelWidth         -columnWidth 2 ($uiInputWidth * 0.5)         -columnWidth 3 ($uiInputWidth * 0.5)         grassGenXRow;                  text             -label "X Value"         floatField             -precision 6             -width ($uiInputWidth * 0.5)             -value -1             grassGenMinX;         floatField             -precision 6             -width ($uiInputWidth * 0.5)             -value 1             grassGenMaxX;         setParent ..;  // Return to column layout  rowLayout         -numberOfColumns 3         -columnAttach 1 "right" 5         -columnWidth 1 $uiLabelWidth         -columnWidth 2 ($uiInputWidth * 0.5)         -columnWidth 3 ($uiInputWidth * 0.5)         grassGenZRow;         text             -label "Z Value"         floatField             -precision 6             -width ($uiInputWidth * 0.5)             -value -1             grassGenMinZ;         floatField             -precision 6             -width ($uiInputWidth * 0.5)             -value 1             grassGenMaxZ;         setParent ..;  // Return to column layout  
On the CD  

The text for this script is found on the companion CD-ROM as Chapter_10/project_UI03/v04/grassUI.mel.

This gives us the results in Figure 10. 47. However, we wanted to place labels above the numerical columns.

click to expand
Figure 10.47: The dimension fields are added.

In order to place the labels, although there are only two obvious text controls, we will use another three-column row layout, the code for which will be placed above the row layout definitions for the dimension attributes. In the first of the three columns, we will place an empty text control. In Example 10.49 we place text controls for the labels in the remaining two columns.

Example 10.49: Labels for the float field columns are added.

 rowLayout         -numberOfColumns 3         -cat 2 "both" 5         -cat 3 "both" 5         -columnWidth 1 $uiLabelWidth         -columnWidth 2 ($uiInputWidth * 0.5)         -columnWidth 3 ($uiInputWidth * 0.5)         grassGenLabelRow;         text             -label "";         text             -label "Minimum Value"             -align center;         text             -label "Maximum Value"             -align center;         setParent ..;  // Return to column layout  
On the CD  

The text for this script is found on the companion CD-ROM as Chapter_10/project_UI03/v05/grassUI.mel.

We have also added separator controls in between each of the three distinct sections. This provides the results seen in Figure 10.48.

click to expand
Figure 10.48: The labeled floatFields and the added separators.

Now that we have controls representing all the variables that need to be passed to generateGrass , we will add a button control in Example 10.50.

Example 10.50: Addition of a button.

 button         -height 40         -label "Generate Grass"`; 

However, the results of this produce a less than desirable result. The window appears similar to that in Figure 10.49. Maya windows have the buttons at the bottom, and they always stay at the bottom. They also resize with the resizing of the window.

click to expand
Figure 10.49: Adding the buttons to the columnLayout makes a rather non-dynamic window.

We will move one level up, into the form layout, and we will also add the Close button. We capture the names of the created buttons to use in the form layout. Form layouts allow for exacting attachment based on either the division marker or the edge of another UI element. Unlike other layouts, the positioning of elements is done after creation. After all, we can t attach to a button that does not yet exist. In our case, we will attach the top left corner of the column layout to the top left corner of the window. We will also attach the bottom of the column layout to the top of the of the Generate Grass button. That button will occupy 75% of the horizontal dimensions of the window, and the Close button will occupy the remaining 25%, and is attached to the right side of the window. Example 10.51 replaces the button added in Example 10.50.

Example 10.51: Attaching the buttons to the formLayout.

 setParent ..; //  Return to the form layout  string $grassGenButton = `button                                 -height 40                                 -label "Generate Grass"`;     string $grassCloseUIButton = `button                                     -height 40                                     -label "Close"                                     -command "deleteUI grassUI"`;     setParent ..;  // Return to the window  formLayout -edit             -attachForm $grassColumn "top" 2             -attachForm $grassColumn "left" 2             -attachControl                 $grassColumn "bottom" 2 $grassGenButton             -attachForm $grassColumn "right" 2                  -attachNone $grassGenButton "top"             -attachForm $grassGenButton "left" 2             -attachForm $grassGenButton "bottom" 2             -attachPosition $grassGenButton "right" 0 75             -attachNone $grassCloseUIButton "top"             -attachPosition $grassCloseUIButton "left" 0 75             -attachForm $grassCloseUIButton "bottom" 2             -attachPosition                  $grassCloseUIButton "right" 2 100             $grassGenForm; 
On the CD  

The text for this script is found on the companion CD-ROM as Chapter_10/project_UI03/v06/grassUI.mel.

Executing this code gives the window shown in Figure 10.50.

click to expand
Figure 10.50: Now using the formLayout to control element placement.

Because we are interacting with the users, we can provide them extra information that could be useful, such as how much grass they are about to create. In Example 10.52 we add a text control to the bottom of the column layout.

Example 10.52: Addition of a text control to give user feedback.

 text         -align left         grassGenFeedback         ; 

We then need a way to update it whenever the user modifies anything in the interface. To do this, we will create a new global procedure, held in the same file, called updateGrassUI . Using procedures to update UI windows is also how reactive UIs are built, such as enabling controls if the user selects a checkbox, or even enabling an entire layout type. For example, the UI creation script could create a scriptJob that rebuilds the UI whenever the selection changes, enabling a tabLayout if more than one object is selected.

Our UI updating procedure uses the same math as our generateGrass script. In fact, it s a simple matter of copying and pasting the line of code from that script. To gather the values for each of variables, in Example 10.53 we query the controls used in the UI. This is why clear, meticulous naming of UI controls is needed.

Example 10.53: A separate procedure to update the user feedback area.

 global proc updateGrassUI ()     {     float $maxX = `floatField query                             -value grassGenMinX`;     float $minX = `floatField query                             -value grassGenMaxX`;     float $maxZ = `floatField query                             -value grassGenMinZ`;     float $minZ = `floatField query                             -value grassGenMaxZ`;     float $density = `floatSliderGrp query                             -value grassGenDensity`;     int $amountToCreate =          abs ((($maxX - $minx)             * ($maxZ - $minZ))             * (($density / 100.0)             * 325)); 

After calculating the value, we use the text command again, this time in edit mode, to update the text field. An inline string addition statement, shown in Example 10.54, produces the desired result.

Example 10.54: The actual command to update the text control.

 text -edit         -label ("This will create "                 + $amountToCreate                 + " blades of grass")         grassGenFeedback         ;     } 

To have the textField update whenever one of the controls has its value changed, we add the argument -changeCommand updateGrassUI to each of the controls. After doing so, we also add the updateGrassUI command to the script immediately before issuing the showWindow command, ensuring that the textField is correct when the window is first created. The window, seen in Figure 10.51, now updates with the total number of grass that will be created.

click to expand
Figure 10.51: The finished window.
On the CD  

The text for this script is found on the companion CD-ROM as Chapter_10/project_UI03/v07/grassUI.mel.

Notice that the window has been resized to a more compact, pleasing size. To get this result, we simply resize the window to the desired size. Then, in Script Editor, we issue the command in Example 10.55.

Example 10.55: Finding the size of the current Grass Generator window.

 window query widthHeight grassUI; 

We can take the resulting values and plug them into the window definition.

To add functionality to the Generate Grass button, and still retain the possibility of issuing the command from the command line, we will create another sub-procedure. This procedure, entitled makeGrass , simply gathers information from the UI, and issues the generateGrass command with the values. Note that the menu is a 1-based index, not a 0-based index, as arrays are. In Example 10.56 we use a switch statement to convert the value held in the menu to the string generateGrass expects.

Example 10.56: This procedure acts as an intermediary between the UI and the command line version of the script.

 global proc makeGrass ()     {     int $styleVal = `optionMenu -query                         -select grassGenStyleDropdown`;     int $detailVal = `optionMenu -query                         -select grassGenDetailDropdown`;     float $maxX = `floatField query                         -value grassGenMinX`;     float $minX = `floatField query                         -value grassGenMaxX`;     float $maxZ = `floatField query                         -value grassGenMinZ`;     float $minZ = `floatField query                         -value grassGenMaxZ`;     float $density = `floatSliderGrp query                         -value grassGenDensity`;     string $style;     switch ($styleVal)         {         case 1:             $style = "short";             break;         case 2:             $style = "normal";             break;         case 3:             $style = "long";             break;         case 4:             $style = "very_long";             break;         }     string $detail;     switch ($detailVal)         {         case 1:             $detail = "low";             break;         case 2:             $detail = "medium";             break;         case 3:             $detail = "high";             break;          }     generateGrass $style                     $detail                     $density                     $minx                     $maxX                     $minZ                     $maxZ ;     } 

While the UI is finalized, matches the original design, and is fully functional, there is one final aspect we can add to improve the user interaction. One of the useful things Maya does is remember the settings a user has selected. We can add these with the optionVar command.

Option Variables

The first step to using option variables is to create them. Because the command to create and to modify option variables is identical, to avoid overwriting any previous settings we protect them with if statements.

At the beginning of the UI creation script, we add Example 10.57, which adds the optionVars with default values if they do not already exist.

Example 10.57: The addition of optionVar commands.

  // Add Option Variables  if (!`optionVar -exists "tmcGrassGenType"`)         optionVar -intValue "tmcGrassGenType" 2;     if (!`optionVar -exists "tmcGrassGenDetail"`)         optionVar -intValue "tmcGrassGenDetail" 3;     if (!`optionVar -exists "tmcGrassGenDensity"`)         optionVar -floatValue "tmcGrassGenDensity" 100;     if (!`optionVar -exists "tmcGrassGenMinX"`)         optionVar -floatValue "tmcGrassGenMinX" -1;     if (!`optionVar -exists "tmcGrassGenMaxX"`)         optionVar -floatValue "tmcGrassGenMaxX" 1;     if (!`optionVar -exists "tmcGrassGenMinZ"`)         optionVar -floatValue "tmcGrassGenMinZ" -1;     if (!`optionVar -exists "tmcGrassGenMaxZ"`)         optionVar -floatValue "tmcGrassGenMaxZ" 1; 

Next, in Example 10.58, we assign the values stored in the option variable to variables.

Example 10.58: Gathering data stored in the optionVars.

 int $grassType = `optionVar -query "tmcGrassGenType"`;     int $grassType = `optionVar query                                 "tmcGrassGenDetail"`;     float $grassDensity = `optionVar query                                  "tmcGrassGenDensity"`;     float $grassMinX = `optionVar -query                                  "tmcGrassGenMinX"`;     float $grassMaxX = `optionVar -query                                  "tmcGrassGenMaxX"`;     float $grassMinZ = `optionVar -query                                  "tmcGrassGenMinZ"`;     float $grassMaxZ = `optionVar -query                                  "tmcGrassGenMaxZ"`; 

We can then use these variables in the creation of the controls. To update the option variables with the values used when the grass is generated, we add Example 10.59 to the makeGrass procedure.

Example 10.59: Updating the optionVars with the user s current settings.

 optionVar -intValue "tmcGrassGenType" $style;     optionVar -intValue "tmcGrassGenDetail" $detail;     optionVar -floatValue "tmcGrassGenDensity" $density;     optionVar -floatValue "tmcGrassGenMinX" $minX;     optionVar -floatValue "tmcGrassGenMaxX" $maxX;     optionVar -floatValue "tmcGrassGenMinZ" $minZ;     optionVar -floatValue "tmcGrassGenMaxZ" $maxZ; 
On the CD  

The text for this script is found on the companion CD-ROM as Chapter_10/project_UI03/final/grassUI.mel.

Now, whenever the Generate Grass button is pressed, the option variables are updated. If we change the values, generate grass, and re-run the script, the values are the same as before.

Project Conclusion and Review

In addition to building a UI using the form layout, we learned how to use optionVar to store user settings. Of course, use of optionVar is not limited to being used in a UI. One thing to always keep in mind with option variables is that because they are all stored in one location, unique naming is mandatory.

Project Script Review

 global proc grassUI ()     {  // Add Option Variables  if (!`optionVar -exists "tmcGrassGenType"`)         optionVar -intValue "tmcGrassGenType" 1;     if (!`optionVar -exists "tmcGrassGenDensity"`)         optionVar -floatValue "tmcGrassGenDensity" 100;     if (!`optionVar -exists "tmcGrassGenMinX"`)         optionVar -floatValue "tmcGrassGenMinX" -1;     if (!`optionVar -exists "tmcGrassGenMaxX"`)         optionVar -floatValue "tmcGrassGenMaxX" 1;     if (!`optionVar -exists "tmcGrassGenMinZ"`)         optionVar -floatValue "tmcGrassGenMinZ" -1;     if (!`optionVar -exists "tmcGrassGenMaxZ"`)         optionVar -floatValue "tmcGrassGenMaxZ" 1;          int $grassType = `optionVar -query "tmcGrassGenType"`;     float $grassDensity = `optionVar -query                                  "tmcGrassGenDensity"`;     float $grassMinX = `optionVar -query "tmcGrassGenMinX"`;     float $grassMaxX = `optionVar -query "tmcGrassGenMaxX"`;     float $grassMinZ = `optionVar -query "tmcGrassGenMinZ"`;     float $grassMaxZ = `optionVar -query "tmcGrassGenMaxZ"`;     if(`window -exists grassUI` != 1)         {         int $uiLabelWidth = 140;         int $uiInputWidth = 240;         int $uiWidth = ($uiLabelWidth + $uiInputWidth);              window             -maximizeButton false             -resizeToFitChildren false             -title "Grass Generator"             -iconName "Grass Generator"             -menuBar false             -wh 448 274             grassUI;         string $grassGenForm = `formLayout                                     -numberOfDivisions 100`;              string $grassColumn = `columnLayout                                 -adjustableColumn true                                 -rowSpacing 5`;         rowLayout             -numberOfColumns 4             -columnAttach 1 "right" 5             -columnAttach 2 "both" 5             -columnAttach 3 "right" 5             -columnAttach 4 "both" 5             -columnWidth 1 $uiLabelWidth             -columnWidth 3 $uiLabelWidth             ;             text                 -label "Grass Style"                 -annotation                 "Select Grass Style.";             optionMenu                 -label ""                 grassGenStyleDropdown;                 menuItem -label "Short";                 menuItem -label "Normal";                 menuItem -label "Long";                 menuItem -label "Very Long";             text                 -label "Detail"                 -annotation                 "Select Amount of Detail.";             optionMenu                 -label ""                 grassGenDetailDropdown;                 menuItem -label "Low";                     menuItem -label "Medium";                 menuItem -label "High";         separator -height 10;              rowLayout             -numberOfColumns 3             -columnAttach 1 "right" 5             -columnWidth 1 $uiLabelWidth             -columnWidth 2 $uiInputWidth             grassDensityRow;                  text                 -label "Density"                 -annotation                     "Set the density parameter for the grass.";             floatSliderGrp                 -field true                 -minValue 0                 -maxValue 100                 -changeCommand updateGrassUI                 -value $grassDensity                 grassGenDensity;             text -label "0% - 100%";             setParent ..;              separator -height 10;              rowLayout             -numberOfColumns 3             -columnAttach 2 "both" 5             -columnAttach 3 "both" 5             -columnWidth 1 $uiLabelWidth             -columnWidth 2 ($uiInputWidth * 0.5)             -columnWidth 3 ($uiInputWidth * 0.5)             grassGenLabelRow;                  text                 -label "";             text                 -label "Minimum Value"                 -align "center";             text                 -label "Maximum Value"                 -align "center";             setParent ..;              rowLayout             -numberOfColumns 3             -columnAttach 1 "right" 5             -columnWidth 1 $uiLabelWidth             -columnWidth 2 ($uiInputWidth * 0.5)             -columnWidth 3 ($uiInputWidth * 0.5)             grassGenXRow;                  text                 -label "X Value"             floatField                 -precision 6                 -width ($uiInputWidth * 0.5)                 -changeCommand updateGrassUI                 -value $grassMinX                 grassGenMinX;             floatField                 -precision 6                 -width ($uiInputWidth * 0.5)                 -changeCommand updateGrassUI                 -value $grassMaxX                 grassGenMaxX;             setParent ..;              rowLayout             -numberOfColumns 3             -columnAttach 1 "right" 5             -columnWidth 1 $uiLabelWidth             -columnWidth 2 ($uiInputWidth * 0.5)             -columnWidth 3 ($uiInputWidth * 0.5)             grassGenZRow;                  text                 -label "Z Value"             floatField                 -precision 6                 -width ($uiInputWidth * 0.5)                 -changeCommand updateGrassUI                 -value $grassMinZ                 grassGenMinZ;             floatField                 -precision 6                 -width ($uiInputWidth * 0.5)                 -changeCommand updateGrassUI                 -value $grassMaxZ                 grassGenMaxZ;             setParent ..;              separator -height 10;              text             -label ("This will create "                     + "0"                     + " blades of grass")             -align left             grassGenFeedback             ;              setParent ..;              string $genButton = `button                                 -height 40                                 -label "Generate Grass"                                 -command "makeGrass"`;              string $closeUIButton = `button                                 -height 40                                 -label "Close"                                 -command "deleteUI grassUI"`;              setParent ..;              formLayout -edit             -attachForm $grassColumn "top" 2             -attachForm $grassColumn "left" 2             -attachControl $grassColumn "bottom" 2 $genButton             -attachForm $grassColumn "right" 2                  -attachNone $grassGenButton "top"             -attachForm $grassGenButton "left" 2             -attachForm $grassGenButton "bottom" 2             -attachPosition $grassGenButton "right" 0 75                  -attachNone $grassCloseUIButton "top"             -attachPosition $grassCloseUIButton "left" 0 75             -attachForm $grassCloseUIButton "bottom" 2             -attachPosition $grassCloseUIButton "right" 2 100             $grassGenForm;              updateGrassUI;         showWindow grassUI;         }     }          global proc updateGrassUI ()     {     float $maxX = `floatField -query -value grassGenMinX`;     float $minX = `floatField -query -value grassGenMaxX`;     float $maxZ = `floatField -query -value grassGenMinZ`;     float $minZ = `floatField -query -value grassGenMaxZ`;     float $density = `floatSliderGrp -query                                 -value grassGenDensity`;          int $amountToCreate =              abs ((($maxX-$minX)                 *                 ($maxZ-$minZ)) * (($density / 100.0)                 *                 325)) ;         text             -edit             -label ("This will create "                     + $amountToCreate                     + " blades of grass")             grassGenFeedback             ;     }          global proc makeGrass ()     {     int $styleVal = `optionMenu -query                         -select  grassGenStyleDropdown`;     int $detailVal = `optionMenu -query                         -select grassGenDetailDropdown`;     float $maxX = `floatField -query -value grassGenMinX`;     float $minX = `floatField -query -value grassGenMaxX`;     float $maxZ = `floatField -query -value grassGenMinZ`;     float $minZ = `floatField -query -value grassGenMaxZ`;     float $density = `floatSliderGrp query -value                                     grassGenDensity`;          string $style;          switch ($styleVal)         {         case 1:             $style = "short";             break;         case 2:             $style = "normal";             break;         case 3:             $style = "long";             break;         case 4:             $style = "very_long";             break;         }     string $detail;     switch ($detailVal)         {         case 1:             $detail = "low";             break;         case 2:             $detail = "medium";             break;         case 3:             $detail = "high";             break;         }     optionVar -intValue "tmcGrassGenType" $style;     optionVar -intValue "tmcGrassGenDetail" $detail;     optionVar -floatValue "tmcGrassGenDensity" $density;     optionVar -floatValue "tmcGrassGenMinX" $minX;     optionVar -floatValue "tmcGrassGenMaxX" $maxX;     optionVar -floatValue "tmcGrassGenMinZ" $minZ;     optionVar -floatValue "tmcGrassGenMaxZ" $maxZ;          generateGrass $style                     $detail                     $density                     $minx                     $maxX                     $minZ                     $maxZ ;     } 



The MEL Companion
The MEL Companion: Maya Scripting for 3D Artists (Charles River Media Graphics)
ISBN: 1584502754
EAN: 2147483647
Year: 2003
Pages: 101

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net