首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MEL查询所选按钮

MEL查询所选按钮
EN

Stack Overflow用户
提问于 2016-03-23 19:22:40
回答 1查看 1.7K关注 0票数 0

我刚开始用MEL写剧本。我有两个单选按钮,一个和两个。当选择单选按钮‘2’时,我希望脚本选择我在场景中创建的两个多维数据集对象(cube1和cube2),这样当我使用“旋转”按钮(一个常规的按钮)时,两个立方体都会旋转。

另一方面,如果选择单选按钮“one”,那么当我按旋转按钮时,其中只有一个(cube1)应该旋转。

我的单选按钮如下:

代码语言:javascript
复制
  $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度。这是目前没有链接到我的单选按钮。

代码语言:javascript
复制
button -label "rotate" -command "setAttr cube1.rotateZ `floatSliderGrp -q -value 30.0`";

有什么想法?我应该查询单选按钮的状态吗?这对我来说用另一种语言就容易多了!我可以看到自己在说“如果$radiotwo.pressed,那么cube1.rotateZ && cube2.rotateZ”

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-23 21:51:10

所有Maya项目都是完全命令式的:您必须发出命令并获得结果,没有“state”:“按钮”或任何您将用于发出命令的对象的字符串名称。

要获取在集合上调用radioCollection -q -select的无线电收集的状态,它将返回所选单选按钮的名称;您可以使用它来驱动逻辑。

代码语言:javascript
复制
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)`;

修改单选按钮和get_radio_state($radiocol);它应该返回所选按钮的名称。

如果您已经熟悉其他语言,您可能应该跳过MEL,直接跳到maya :它更有能力,更少调整。大量讨论这里这里

作为比较,这里有一个相同想法的python版本:

代码语言:javascript
复制
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)

在这里,按钮执行与前面示例中的print语句相同的操作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36186958

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档