昨日は解決した(というか、正解ではないが回避策がわかった)ラジオボタン問題。
mixiのコミュニティで正しい解決法を聞いてみようと思いうまくいかない例を
作ってみたが、なぜかうまく動いてしまう。
いろいろ試すうちに”ウィンドウをたくさん作って消す”ような動作をさせていると
おかしくなる事がわかった。
つまり“MAYA操作中にできるゴミデータが変数に残っている”のが原因じゃなかろうか?
★★★★これでウィンドウをたくさん出しては消し、とやるとおかしくなる★★★★
global proc makePrimitive()
{
global string $radioCollection1;
string $selected;
$selected = `radioCollection -q -select $radioCollection1`;
if($selected == "rB1")
{
polySphere;
}
else if($selected == "rB2")
{
polyCube;
}
}
global proc btn()
{
string $windowName = `window -title "test"`;
columnLayout;
text -label "make Primitive";
string $radioCollection1 = `radioCollection`;
radioButton -label "make Sphere" -select rB1;
radioButton -label "make Cube" rB2;
button -label " Aplly " -command "makePrimitive()";
showWindow;
}
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
なので変数をクリアするおまじないを入れてみた。
★★★★★★★★おまじないをいれた改良版★★★★★★★★
global proc makePrimitive()
{
global string $radioCollection1;
string $selected;
$selected = `radioCollection -q -select $radioCollection1`;
if($selected == "rB1")
{
polySphere;
}
else if($selected == "rB2")
{
polyCube;
}
}
global proc btn()
{
global string $radioCollection1;
$radioCollection1 = "";
string $windowName = `window -title "test"`;
columnLayout;
text -label "make Primitive";
string $radioCollection1 = `radioCollection`;
radioButton -label "make Sphere" -select rB1;
radioButton -label "make Cube" rB2;
button -label " Aplly " -command "makePrimitive()";
showWindow;
}
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
いまのところうまく動作しているようだ。昔作って今動かなくなっている別の
スクリプトにも組み込んでみたが正しく動作した。
どうやらこれが正解のようだ。 こういう仕様はアレかね、動的な扱いができるスクリプトで
あるが故に、ある物体の名前が同じならそれは絶対同一の物体であることを保証できないっつう
ことですかねえ。
なんにせよ変数の初期化やウィンドウの存在確認は懇ろにやっておくにこしたことはないようだ。
.
0 件のコメント:
コメントを投稿