Mitchel Clayton

mitchel.clayton[AT]gmail.com

MEL: UI

This is the result of creating a user interface for my MEL matrix script.

Variant Renders

UI MEL Script

global string $sliderWin;
global string $percent;
global string $numSlider;
global string $cubes;
global string $subdivisions;
global string $SC1;
global string $SC2;
global string $SC3;
  
//--------------------------------------------------
// Echoes the value of a slider in the script window
//--------------------------------------------------
global proc createLattice() {
    global string $percent;
    global string $numSlider;
    global string $subdivisions;
    global string $height;
    global string $width;
    global string $depth;
    global string $cubes;
  
    float $d = `floatSliderGrp -q -v $depth`;
    float $h = `floatSliderGrp -q -v $height`;
    float $w = `floatSliderGrp -q -v $width`;
    int $subD = `intSliderGrp -q -v $subdivisions`;
    int $num = `intSliderGrp -q -v $numSlider`;
    int $num2 = `intSliderGrp -q -v $cubes`;
    float $p = `floatSliderGrp -q -v $percent`;
  
    latticeCreate($num,$p,$subD,$w,$h,$d,$num2);
}
  
global proc latticeExtrude(){
    global string $SC1;
    global string $SC2;
    global string $SC3;
  
    float $scale1 = `floatSliderGrp -q -v $SC1`;
    float $scale2 = `floatSliderGrp -q -v $SC2`;
    float $scale3 = `floatSliderGrp -q -v $SC3`;
    extrude2($scale1, $scale2, $scale3);
  
}
  
//--------------------------------------------------
// Adds sliders and buttons to the window
//--------------------------------------------------
global proc addUIWidgets() {
    global string $percent;
    global string $numSlider;
    global string $subdivisions;
    global string $height;
    global string $width;
    global string $depth;
    global string $cubes;
    global string $SC1;
    global string $SC2;
    global string $SC3;
    
    columnLayout -rowSpacing 5;
    image -image "D:/user/My Documents/maya/2018/prefs/icons/LatticeTitle.png";
    
    //Object Parameters
    frameLayout -collapsable 1 -label "Object Parameters" -w 400;
    
    $cubes = `intSliderGrp -columnWidth 1 120
                        -label "# of cubes"
                        -field true
                        -value 100
                        -min 1 -max 500`;
    
    $depth = `floatSliderGrp -columnWidth 1 120
                        -label "Cube Depth"
                        -field true
                        -value 1
                        -min .1 -max 5`;
    $height = `floatSliderGrp -columnWidth 1 120
                        -label "Cube Height"
                        -field true
                        -value 1
                        -min .1 -max 5`;
    $width = `floatSliderGrp -columnWidth 1 120
                        -label "Cube Width"
                        -field true
                        -value 1
                        -min .1 -max 5`;
                        
    $subdivisions= `intSliderGrp -columnWidth 1 120
                        -label "# of Subdivisions"
                        -field true
                        -value 1
                        -min 1 -max 4`;
    setParent ..;
                
    //Selection Parameters
    frameLayout -collapsable 1 -label "Face Selection Parameters" -w 400;
    
    $percent = `floatSliderGrp -columnWidth 1 120
                        -label "Percentage Selection"
                        -field true
                        -value 0.5
                        -min .0 -max 1.0`;
    setParent ..;
    
    //Group Parameters
    frameLayout -collapsable 1 -label "Group Parameters" -w 400;
    $numSlider = `intSliderGrp -columnWidth 1 120
                        -label "# of Lattice Groups"
                        -field true
                        -value 2
                        -min 1 -max 6`;
    setParent ..;
  
    button -w 400 -label "Create Lattice" -command "createLattice";
    
    //Extrusions
    frameLayout -collapsable 1 -label "Extrusions";
    
    $SC1 = `floatSliderGrp -columnWidth 1 120
                -label "Extrusion Length Max 1"
                -field true
                -value 5
                -min .1 -max 20`;    
    $SC2 = `floatSliderGrp -columnWidth 1 120
                -label "Extrusion Length Max 2"
                -field true
                -value 5
                -min .1 -max 20`;
                
    $SC3 = `floatSliderGrp -columnWidth 1 120
                -label "Extrusion Length Max 3"
                -field true
                -value 5
                -min .1 -max 20`;
                    
     button -w 400 -label "Extrude" -command "latticeExtrude";
  
    //delete Parameters
    frameLayout -collapsable 1 -label "Delete Options";
     button -w 400 -label "Delete Lattice Groups" -command "deleteAll";
    
    }
  
//--------------------------------------------------
// Main proc
//--------------------------------------------------
global proc latticeUI() {
global string $sliderWin; 
    
    int $doesExist = `window -exists $sliderWin`;
    if($doesExist == 0) {
        $sliderWin = `window -w 400 -h 120
                            -retain
                            -topLeftCorner 500 1000
                            -title "Lattice Creation"`;
        addUIWidgets();
        }
    showWindow $sliderWin;
}

Execution / Installation

 

1. Download the zip archive here (right click > Save As..)

2. Copy the latticeUI.mel file to \Users\-username-\Documents\maya\scripts\ Folder.

3. Copy the latticeTitle.png into your \Documents\maya\2018\prefs\icons folder.

3. Start Maya.

4. In the Script Editor window, type latticeUI; (case sensitive) and execute the command.

Conclusion

Creating UI for my previous script has taught me a lot more about MEL and has given me a lot of ideas on how to further update my lattice script to be a more useful tool. I feel that I have a good understanding of the usefulness of MEL and feel I could create MEL scripts to help in my work flow.