いくつかの項目の中から、ひとつ以上の項目を選べるようにしたい場合は、チェックボックスを使用します。
チェックボックスも、スライダーと同じように、
まずチェックボックスを作成し、
その後で、現在のチェックボックスの状態を調べます。
チェックボックスに、チェックが入っているかどうかを調べるには、以下の方法があります。
ret = pymel.core.checkBox('sampleCheckBox', q=True, value=True)
if ret:
チェックされている場合に実行したい Python 文
または
if pymel.core.checkBox('sampleCheckBox', q=True, value=True):
チェックされている場合に実行したい Python 文
pymel.core.checkBox('sampleCheckBox', q=True, value=True) によってオンなら True、オフなら False が返されます。
ret = pymel.core.checkBox('checkButton1', q=True, value=True)
if ret:
チェックされている場合に実行したい Python 文;
または
if pymel.core.checkBox('checkButton1', q=True, value=True):
チェックされている場合に実行したい Python 文;
チェックボックスにチェックをいれると、 X 方向にスケールされた球を作る GUI を作ってみましょう。
以下は、チェックボックスにチェックが入っている時にだけ、 X 方向に 2.0 のスケールをかけるスクリプトです。
また、今回は、クリックするとウインドウを消去する 閉じる ボタンをつけてみましょう。
global proc makeSphere()
{
global string $checkBox1;
float $x = 1.0;
if(`checkBox -q -value $checkBox1`)
{
$x = 2.0;
}
sphere;
scale $x 1.0 1.0;
}
string $windowName = `window -title "checkBox1"`;
columnLayout;
text -label "球作成";
string $checkBox1 = `checkBox -label "スケールX"`;
button -label "作成" -command "makeSphere()";
button -label "閉じる" -command ("deleteUI " + $windowName);
showWindow;
import pymel.core
def makeSphere():
x = 1.0
if pymel.core.checkBox(checkBox1, q=True, value=True):
x = 2.0
pymel.core.sphere()
pymel.core.scale([x, 1.0, 1.0])
windowName = pymel.core.window(title='checkBox1')
pymel.core.columnLayout()
pymel.core.text(label=u'球作成')
checkBox1 = pymel.core.checkBox(label=u'スケールX')
pymel.core.button(label=u'作成', command='makeSphere()')
pymel.core.button(label=u'閉じる', command=('pymel.core.deleteUI("' + windowName + '")'))
pymel.core.showWindow()
import pymel.core
def makeSphere():
x = 1.0
if pymel.core.checkBox(checkBox1, q=True, value=True):
x = 2.0
pymel.core.sphere()
pymel.core.scale([x, 1.0, 1.0])
windowName = pymel.core.window(title='checkBox1')
pymel.core.columnLayout()
pymel.core.text(label=u'球作成')
checkBox1 = pymel.core.checkBox(label=u'スケールX')
pymel.core.button(label=u'作成', command='makeSphere()')
pymel.core.button(label=u'閉じる', command=('pymel.core.deleteUI("' + windowName + '")'))
pymel.core.showWindow()