将过程链接到每个按钮命令 maya [英] Link procedure to each button command maya

查看:22
本文介绍了将过程链接到每个按钮命令 maya的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了这个脚本来创建具有不同颜色值的两种材质.如何附加此程序,以便当我单击颜色 1 按钮时,它会在单击第二个按钮时创建材质颜色 1 和颜色 2.如果有更好的实现这一点的方法是python.请告诉我

I made this script that creates two material with different color values.How can I attach this procedure so that when I click color 1 button it creates material color 1 and color 2 when I click second button.If there is a much better way to achieve this is python.Please let me know

global string $list_of_names[];
global float $matColor[];
$list_of_names = {"color1","color2"};
$matColor = { 1.0,0.355,0.5,0.545,0.5,1.0};


global proc create() {
global string $list_of_names[];
global float $matColor[];

   for ($i=0; $i<`size $list_of_names`; ++$i){
        shadingNode -asShader VRayMtl -n $list_of_names;
        setAttr ($list_of_names[$i] + ".color") -type double3 $matColor[($i*3)] $matColor[($i*3)+1] $matColor[($i*3)+2];                   
    } 

}


window -width 150;
columnLayout -adjustableColumn true;

for ($i=0; $i<`size $list_of_names`; ++$i){
    button -label $list_of_names[$i] -command "create()";
}

showWindow;

推荐答案

根据对您的问题的评论,这应该是您要查找的内容:

Based on the comments on your question, this should be what you are looking for:

import functools

import maya.cmds

buttons = {
    'color1': (1.0, 0.0, 0.0),
    'color2': (0.0, 1.0, 0.0),
}

def button_callback(shader_color):
    print shader_color
    maya.cmds.shadingNode(...)
    maya.cmds.setAttr(...)


w = maya.cmds.window(width=150)
maya.cmds.columnLayout( adjustableColumn=True)

for btn in buttons:
    maya.cmds.button(
        label=btn,
        command=functools.partial(button_callback, buttons[btn])
    )

maya.cmds.showWindow()

基本上这段代码做的事情和你在 MEL 中做的一样,但是使用 python结构"(因为 python 是 Maya 的一种独立语言,有一些库,比如 functools,可以帮助你做更多的事情MEL 让你做的复杂的事情).

Basically this code does the same thing you are doing in MEL, but using python "structure" (because python is an indipendent language from Maya, has some libraries like functools, that helps you doing more complex things that the one that MEL lets you do).

要了解更多信息,只需查看 google for python 2.7.10+ 文档(这是 Maya 最新版本中使用的文档).

To understand more about it, just look into google for python 2.7.10+ documentation (that is the one used from the last version of Maya).

Maya 还提供了一些关于您可以使用的 Python 函数的文档,而不是 MEL 函数.

Also Maya has some documentation about the python function you can use, instead of the MEL ones.

这篇关于将过程链接到每个按钮命令 maya的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆