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

查看:102
本文介绍了将过程链接到每个按钮命令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"structure"(因为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以获取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天全站免登陆