print ($x + "\n");
sphere -n "mySphere1"; group -n myGroup mySphere1; sphere -n "mySphere1";作成後に、以下のコマンドで球体を選択しようとするとエラーになります。
global proc testWindow()
{
$winName = `window -title "テスト"`;
columnLayout;
button -label "閉じる" -command "deleteUI $winName";
showWindow;
}
$winName という変数に作られたウインドウの名前を代入していますが、
この変数はプロシージャ testWindow の内部変数なので、
このプロシージャの実行が終るとともに消えてしまいます。
ですから、ボタンを押した時に deleteUI コマンドによって
$winName を参照しようとしても失敗してしまいます。
string $winName; // 外部変数$winName
global proc testWindow()
{
global string $winName; // この変数は外部変数の$winName
$winName = `window -title "テスト"`;
columnLayout;
button -label "閉じる" -command "deleteUI $winName";
showWindow;
}
または、以下のようにウインドウの名前を、コマンドの文字列へあらかじめ入れておきます。
global proc testWindow()
{
$winName = `window -title "テスト"`;
columnLayout;
button -label "閉じる" -command ("deleteUI " + $winName);
showWindow;
}
window;
columnLayout;
setParent ..; // 省略しない
showWindow;
これでウインドウを表示しておいてから button コマンドなどを実行すると、
実行するたびに部品が追加されてゆきます。
window;
columnLayout;
string $columnLayoutName1 = `columnLayout`;
button -label "ボタン1";
setParent ..;
string $columnLayoutName2 = `columnLayout`;
button -label "ボタン2";
setParent ..;
showWindow;
setParent $columnLayoutName1;
button -label "追加ボタン";
setParent ..;
uiTemplate testTemplate; // テンプレートオブジェクトを作ります
columnLayout -defineTemplate testTemplate // そのテンプレートオブジェクトに対して定義します
-columnAlign right
-columnOffset right 10
-columnWidth 20
-rowSpacing 10;
window;
columnLayout -useTemplate testTemplate;
button -label "ボタン1";
button -label "ボタン2";
showWindow;
window;
columnLayout -useTemplate testTemplate;
button -label "ボタン3";
button -label "ボタン4";
showWindow;