MEL 查询选定的按钮
MEL Querying a selected button
我刚开始使用 MEL 编写脚本。
我有两个单选按钮,一和二。当单选按钮 'two' 被 selected 时,我希望脚本 select 我在场景中创建的两个立方体对象(cube1 和 cube2),这样当我使用我的 'rotate' 按钮(普通按钮),两个立方体都旋转。
另一方面,如果单选按钮 'one' 是 selected,那么当我按下旋转按钮时,只有其中一个 (cube1) 应该旋转。
我的单选按钮如下:
$radio1 = `radioCollection`;
//my radio buttons
$one = `radioButton -label "1 cube"`;
$two = `radioButton -label "2 cubes"`;
radioCollection -edit -select $one $radio1; //so that this one is selected by default
对于旋转按钮,我有这个按钮可以将立方体对象 'cube1' 旋转 30 度。这目前没有链接到我的单选按钮。
button -label "rotate" -command "setAttr cube1.rotateZ `floatSliderGrp -q -value 30.0`";
想法?我应该查询单选按钮的状态吗?如果用另一种语言,这对我来说会容易得多!我可以看到自己在说 "if $radiotwo.pressed, then cube1.rotateZ && cube2.rotateZ"
所有 Maya UI 项目都是完全命令式的:您必须发出命令并获得结果,没有 'state':'button' 或其他任何东西都只是字符串名称您将用于发出命令的对象
要获取您在集合上调用 radioCollection -q -select
的单选集合状态,这将 return 所选单选按钮的名称;你会用它来驱动你的逻辑。
string $w = `window`;
string $c = `columnLayout`;
string $radiocol = `radioCollection "radio buttons"`;
string $one_cube = `radioButton -label "1 cube"`;
string $two_cube = `radioButton -label "2 cubes"`;
radioCollection -edit -select $one_cube $radiocol;
showWindow $w;
global proc string get_radio_state(string $radio)
{
string $selected = `radioCollection -q -select $radio`;
return `radioButton -q -label $selected`;
}
print `get_radio_state($radiocol)`;
fiddle 带有单选按钮和 get_radio_state($radiocol)
;它应该 return 所选按钮的名称。
如果您已经熟悉其他语言,您可能应该跳过 MEL,直接跳到 Maya python:它功能更强大,调整更少。大量讨论 here and here
为了比较,这里有一个相同想法的 python 版本:
w = cmds.window()
c =cmds.columnLayout()
rc = cmds.radioCollection()
cmds.radioButton('one', label="1 cube")
cmds.radioButton('two', label = "2 cubes")
def print_selected(*ignore):
print "selected", cmds.radioCollection(rc, q=True, select=True)
btn = cmds.button("print selected", command=print_selected)
cmds.showWindow(w)
这里的按钮与前面例子中的打印语句做同样的事情
我刚开始使用 MEL 编写脚本。 我有两个单选按钮,一和二。当单选按钮 'two' 被 selected 时,我希望脚本 select 我在场景中创建的两个立方体对象(cube1 和 cube2),这样当我使用我的 'rotate' 按钮(普通按钮),两个立方体都旋转。
另一方面,如果单选按钮 'one' 是 selected,那么当我按下旋转按钮时,只有其中一个 (cube1) 应该旋转。
我的单选按钮如下:
$radio1 = `radioCollection`;
//my radio buttons
$one = `radioButton -label "1 cube"`;
$two = `radioButton -label "2 cubes"`;
radioCollection -edit -select $one $radio1; //so that this one is selected by default
对于旋转按钮,我有这个按钮可以将立方体对象 'cube1' 旋转 30 度。这目前没有链接到我的单选按钮。
button -label "rotate" -command "setAttr cube1.rotateZ `floatSliderGrp -q -value 30.0`";
想法?我应该查询单选按钮的状态吗?如果用另一种语言,这对我来说会容易得多!我可以看到自己在说 "if $radiotwo.pressed, then cube1.rotateZ && cube2.rotateZ"
所有 Maya UI 项目都是完全命令式的:您必须发出命令并获得结果,没有 'state':'button' 或其他任何东西都只是字符串名称您将用于发出命令的对象
要获取您在集合上调用 radioCollection -q -select
的单选集合状态,这将 return 所选单选按钮的名称;你会用它来驱动你的逻辑。
string $w = `window`;
string $c = `columnLayout`;
string $radiocol = `radioCollection "radio buttons"`;
string $one_cube = `radioButton -label "1 cube"`;
string $two_cube = `radioButton -label "2 cubes"`;
radioCollection -edit -select $one_cube $radiocol;
showWindow $w;
global proc string get_radio_state(string $radio)
{
string $selected = `radioCollection -q -select $radio`;
return `radioButton -q -label $selected`;
}
print `get_radio_state($radiocol)`;
fiddle 带有单选按钮和 get_radio_state($radiocol)
;它应该 return 所选按钮的名称。
如果您已经熟悉其他语言,您可能应该跳过 MEL,直接跳到 Maya python:它功能更强大,调整更少。大量讨论 here and here
为了比较,这里有一个相同想法的 python 版本:
w = cmds.window()
c =cmds.columnLayout()
rc = cmds.radioCollection()
cmds.radioButton('one', label="1 cube")
cmds.radioButton('two', label = "2 cubes")
def print_selected(*ignore):
print "selected", cmds.radioCollection(rc, q=True, select=True)
btn = cmds.button("print selected", command=print_selected)
cmds.showWindow(w)
这里的按钮与前面例子中的打印语句做同样的事情