PDA

View Full Version : Adding and connecting multiple attribute to multiple objects


stormx22
01-06-2011, 12:55 AM
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

haggi
01-06-2011, 09:52 AM
There is a "code" for the display of - you may guess it - code in the message: The # sign.


global proc cube()
{
int $num = `intSliderGrp -q -v num`;
string $SELECT =` ls -sl`; // <-- this variable is completly unused

for ($x =0 ; $x<$num; $x++)
{
string $pc[] = `polyCube`; //<-- use variables
move (1.5*$x) 0 0 $pc[0];
addAttr -ln "green" -nn "gn" -at double -keyable 1 -min 0 -max 1 $pc[0];
addAttr -ln "blue" -nn "gn" -at double -keyable 1 -min 0 -max 1 $pc[0];
}
.....
...


Maybe you could simply create a color attribute for your cubes and connect them directly to the incansence of your shader. In the color procedures you then assign the colors values to the cube, or because you simply add a shader per cube, why adding these variable at all to the cubes? You can simply directly manipulate the shaders itself. You only have to know how they are named.

pixelranger
01-06-2011, 11:05 AM
basicly you need to loop over the selection and add the attribute to each at a time.

maybe you can pick up a hint from here (http://andrehitsoy.tumblr.com/post/2362033147/09-connect-attrs-to-control-object)

CGTalk Moderation
01-06-2011, 11:05 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.