いくつかある項目の中から複数または、一つだけの項目を選びたい時にはcheckBoxとradioButtonを使用する。
ラジオボタンによってプリミティブ(球、キューブのうちのどれか)を作るGUIを作ってみよう。
以下のスクリプトをradio1.melという名前で作る。
global proc makePrimitive()
{
$selected = `radioCollection -q -select radioCollection1`;
if($selected == "sphereButton")
sphere;
else if($selected == "cubeButton")
nurbsCube;
}
window -title "radioButton1" window1;
columnLayout;
text -label "make Primitive";
radioCollection radioCollection1;
radioButton -label "Sphere" -select sphereButton;
radioButton -label "Cube" cubeButton;
button -label "OK" -command "makePrimitive()";
button -label "Close" -command "deleteUI window1";
showWindow;
global proc makePrimitive()
このプロシージャがOKボタンによって実行される。
$selected = `radioCollection -q -select radioCollection1`;
radioCollection1という名前のラジオコレクションの中で選ばれているラジオボタンを調べて、その名前を$selectedという変数に代入する。
if($selected == "sphereButton")
sphere;
sphereButtonが選ばれていれば、sphereコマンドを実行する。
else if($selected == "cubeButton")
nurbsCube;
cubeButtonが選ばれていれば、nurbsCubeコマンドを実行する。
window -title "radioButton1" window1;
window1という名前でウインドウを作る。
columnLayout;
部品を縦1列に並べる。
text -label "make Primitive";
make Primitiveというテキストを表示。
radioCollection radioCollection1;
radioCollection1という名前でラジオコレクションを作る。
radioButton -label "Sphere" -select sphereButton;
sphereButtonという名前のラジオボタンを作る。
radioButton -label "Cube" cubeButton;
cubeButtonという名前のラジオボタンを作る。
button -label "OK" -command "makePrimitive()";
OKボタンを作る。
button -label "Close" -command "deleteUI window1";
Closeボタンを作る。
showWindow;
ウインドウを表示する。