stormx22
01-05-2011, 11:55 PM
Hi
I just started doing mel scripting and i have a script assignment that im having trouble with.
the assignment is :
Create a window that can control how many cubes and have at least 5 color options.
here is my script:
file -f -new;
//i used several global procedure to do this script//
global proc cube()
//this make the cubes and add the attribute and connect them//
{
int $num = `intSliderGrp -q -v num`;
string $SELECT =` ls -sl`;
for ($x =0 ; $x<$num; $x++)
{
polyCube;
move (1.5*$x) 0 0;
}
select -all;
addAttr -ln "green" -nn "gn" -at double -min 0 -max 1 |cube1;
//my problem is that i don't know how to get the addAttr and setAttr to apply to the selections//
setAttr -e -keyable true |cube1;
addAttr -ln "red" -nn "rd" -at double -min 0 -max 1 |cube1;
setAttr -e -keyable true |cube1;
addAttr -ln "blue" -nn "be" -at double -min 0 -max 1 |cube1;
setAttr -e -keyable true |cube1;
addAttr -ln "yellow" -nn "yw" -at double -min 0 -max 1 |cube1;
setAttr -e -keyable true |cube1;
addAttr -ln "white" -nn "we" -at double -min 0 -max 1 |cube1;
setAttr -e -keyable true |cube1;
addAttr -ln "purple" -nn "pe" -at double -min 0 -max 1 |cube1;
setAttr -e -keyable true |cube1;
addAttr -ln "light blue" -nn "lt be" -at double -min 0 -max 1 |cube1;
setAttr -e -keyable true |cube1;
shadingNode -asShader lambert;
sets -renderable true -noSurfaceShader true -empty -name lambert2SG;
connectAttr -f lambert2.outColor lambert2SG.surfaceShader;
select -r lambert2;
rename lambert2 "box1";
connectAttr -f cube1.red box1.incandescenceR;
//and how to get them connected to the objects//
connectAttr -f cube1.blue box1.incandescenceB;
connectAttr -f cube1.green box1.incandescenceG;
}
global proc Red()
{
setAttr "cube1.red" 1;
}
global proc Blue()
{
setAttr "cube1.blue" 1;
}
global proc Green()
{
setAttr "cube1.green" 1;
}
global proc yellow()
{
setAttr "cube1.green"1;
setAttr "cube1.red" 1;
}
global proc white()
{
setAttr "cube1.green"1;
setAttr "cube1.red" 1;
setAttr "cube1.blue" 1;
}
global proc purple()
{
setAttr "cube1.red" 1;
setAttr "cube1.blue" 1;
}
global proc lightblue()
{
setAttr "cube1.green"1;
setAttr "cube1.blue" 1;
}
global proc Off()
{
setAttr "cube1.green"0;
setAttr "cube1.red" 0;
setAttr "cube1.blue" 0;
}
window -t "26" -widthHeight 600 600;
columnLayout -adjustableColumn true;
frameLayout -l "Cubes" -collapsable true -borderStyle "etchedOut";
columnLayout -columnAttach "both" 5 -rowSpacing 5 -columnWidth 500;
intSliderGrp -l "Number of Cubes" -field true -minValue 0 -maxValue 20 num;
radioButtonGrp -numberOfRadioButtons 4
-l "Color"
-labelArray4 "red" "blue" "green" "yellow"
-on1 Red -on2 Blue -on3 Green -on4 yellow ;
radioButtonGrp -numberOfRadioButtons 3
-l ""
-labelArray3 "white" "purple" "light blue"
-on1 white -on2 purple -on3 lightblue -ofc Off;
button -l "Cubes" -width 50 -c cube;
setParent..;
setParent..;
setParent..;
showWindow;
if you need to change my script alot then please add an explanation to it so i know how to do it and what going on in the script.
thanks for the help
I just started doing mel scripting and i have a script assignment that im having trouble with.
the assignment is :
Create a window that can control how many cubes and have at least 5 color options.
here is my script:
file -f -new;
//i used several global procedure to do this script//
global proc cube()
//this make the cubes and add the attribute and connect them//
{
int $num = `intSliderGrp -q -v num`;
string $SELECT =` ls -sl`;
for ($x =0 ; $x<$num; $x++)
{
polyCube;
move (1.5*$x) 0 0;
}
select -all;
addAttr -ln "green" -nn "gn" -at double -min 0 -max 1 |cube1;
//my problem is that i don't know how to get the addAttr and setAttr to apply to the selections//
setAttr -e -keyable true |cube1;
addAttr -ln "red" -nn "rd" -at double -min 0 -max 1 |cube1;
setAttr -e -keyable true |cube1;
addAttr -ln "blue" -nn "be" -at double -min 0 -max 1 |cube1;
setAttr -e -keyable true |cube1;
addAttr -ln "yellow" -nn "yw" -at double -min 0 -max 1 |cube1;
setAttr -e -keyable true |cube1;
addAttr -ln "white" -nn "we" -at double -min 0 -max 1 |cube1;
setAttr -e -keyable true |cube1;
addAttr -ln "purple" -nn "pe" -at double -min 0 -max 1 |cube1;
setAttr -e -keyable true |cube1;
addAttr -ln "light blue" -nn "lt be" -at double -min 0 -max 1 |cube1;
setAttr -e -keyable true |cube1;
shadingNode -asShader lambert;
sets -renderable true -noSurfaceShader true -empty -name lambert2SG;
connectAttr -f lambert2.outColor lambert2SG.surfaceShader;
select -r lambert2;
rename lambert2 "box1";
connectAttr -f cube1.red box1.incandescenceR;
//and how to get them connected to the objects//
connectAttr -f cube1.blue box1.incandescenceB;
connectAttr -f cube1.green box1.incandescenceG;
}
global proc Red()
{
setAttr "cube1.red" 1;
}
global proc Blue()
{
setAttr "cube1.blue" 1;
}
global proc Green()
{
setAttr "cube1.green" 1;
}
global proc yellow()
{
setAttr "cube1.green"1;
setAttr "cube1.red" 1;
}
global proc white()
{
setAttr "cube1.green"1;
setAttr "cube1.red" 1;
setAttr "cube1.blue" 1;
}
global proc purple()
{
setAttr "cube1.red" 1;
setAttr "cube1.blue" 1;
}
global proc lightblue()
{
setAttr "cube1.green"1;
setAttr "cube1.blue" 1;
}
global proc Off()
{
setAttr "cube1.green"0;
setAttr "cube1.red" 0;
setAttr "cube1.blue" 0;
}
window -t "26" -widthHeight 600 600;
columnLayout -adjustableColumn true;
frameLayout -l "Cubes" -collapsable true -borderStyle "etchedOut";
columnLayout -columnAttach "both" 5 -rowSpacing 5 -columnWidth 500;
intSliderGrp -l "Number of Cubes" -field true -minValue 0 -maxValue 20 num;
radioButtonGrp -numberOfRadioButtons 4
-l "Color"
-labelArray4 "red" "blue" "green" "yellow"
-on1 Red -on2 Blue -on3 Green -on4 yellow ;
radioButtonGrp -numberOfRadioButtons 3
-l ""
-labelArray3 "white" "purple" "light blue"
-on1 white -on2 purple -on3 lightblue -ofc Off;
button -l "Cubes" -width 50 -c cube;
setParent..;
setParent..;
setParent..;
showWindow;
if you need to change my script alot then please add an explanation to it so i know how to do it and what going on in the script.
thanks for the help
