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:
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).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).
Also Maya has some documentation about the python function you can use, instead of the MEL ones.