Maya Mel GUI入门

在写mel程序时,友好的用户界面是很重要的,因此需要掌握一些基本控件的使用方法,在学习的过程中,也留给自己作为笔记,同时也希望能对有需要的人有些帮助。


1.创建一个window,里面可以包含很多的控件,比如基本的button,checkbox,textfield等等

window;
columnLayout;
    text -label "My text";
    button -label "I'm a button";
    checkBox -label "Check Box";
    radioCollection;
        radioButton -label "start";
        radioButton -label "stop";
    floatField -value 3.41;
    textField -text "Hello";
showWindow;


2.控件触发执行相应命令

global proc Create_sphere()
{
    sphere -name "MySphere";
}
 
window;
    columnLayout;
    button -label "My Sphere" -command "Create_sphere()";
showWindow;

Maya Mel GUI入门_第1张图片


3.界面布局,有ColumnLayout,RowLayout,FrameLayout等等

window;
    columnLayout -columnWidth 150;
        button;
        button;
showWindow;

4.确认对话框

$my_confirm = `confirmDialog -title "Confirm" -message "Yes or No"
                -button "YES" -button "NO"
                -defaultButton "YES"    -cancelButton "NO"
                -dismissString "NO"`;
if ($my_confirm == "YES"){
    print "User has picked YES\n";
}
else if ($my_confirm == "NO"){
    print "User has picked NO\n";
}

Maya Mel GUI入门_第2张图片


4.提示框

string $text;
string $my_prompt = `promptDialog
    -title "Rename An Entity"
    -message "Enter Name:"
    -button "OK" -button "Cancel"
    -defaultButton "OK" -cancelButton "Cancel"
    -dismissString "Cancel"`;
 
//get new name of entity
if ($my_prompt == "OK") {
    $text = `promptDialog -query -text`;
    print ("New name for Entity: " + $text + "\n");
}
else if ($my_prompt == "Cancel") {
    print ("OK, fine don't rename....\n");
}


5.获取输入框中的数字

window intFieldTestWin;
columnLayout;
intField intergerField;
showWindow intFieldTestWin;

//then declare an interger variable to store your value

int $intStorage;

//now, type an interger in the window.
//Then, use the infField query mode to query the value of the window into
//the variable. You use the single quote (``) signs for this.

$intStorage = `intField -q -v intergerField`;
print $intStorage;
// To do it the other way around, meaning to put the value of a variable into the field 
// itself, you can try this.
// Declare a variable with a value.

int $intStorage = 20;

// Then use the intField edit mode to input the variable as the arguement
// for the window.

intField -e -v $intStorage intergerField;
// Basically, most UI controls share the same creation/edit/query syntax.


6.取得输入框的值并进行相应的动作

window -t "test";
    gridLayout -numberOfColumns 3 -cellWidthHeight 100 30 -w 300 -h 50;
        text -label "个数:";
        intField -min 1 -max 10 number;
        button -label "生成" -c "test";
showWindow;

proc test()
{
    global string $intFieldName = "";
    int $value;
    $value = `intField -query -value number`;
    print($value);
    
    int $i = 0;
    for($i=1;$i<=$value;++$i)
    {
        polyCylinder -r 1 -h 2 -sx 20 -sy 1 -sz 1 -ax 0 1 0 -rcp 0 -cuv 3 -ch 1;
        polyCylinder -r 1 -h 2 -sx 20 -sy 1 -sz 1 -ax 0 1 0 -rcp 0 -cuv 3 -ch 1;
        move -r 0 1.40901 0 ;
        //scale -r 0.487535 0.487535 0.487535 ;
        $randx = rand(0.2,2);
        $randy = rand(0.2,2);
        $randz = rand(0.2,2);
        scale -r $randx $randy $randz;
        select -r ("pCylinder"+ ($i*2-1)) ("pCylinder"+$i*2) ; 
        move -r ($i*3) 0 0 ;  
    }
}

Maya Mel GUI入门_第3张图片

你可能感兴趣的:(Maya,mel)