Simply Maya User Community

Simply Maya User Community (https://simplymaya.com/forum/index.php)
-   Programming (https://simplymaya.com/forum/forumdisplay.php?f=32)
-   -   getAttr and setAttr in an array (https://simplymaya.com/forum/showthread.php?t=33906)

Falott 21-03-2010 10:19 AM

getAttr and setAttr in an array
 
lets say I have a pointlight I want to query the colorRGB values from and copy those values into a spotlights colorRGB.
(I need to use an array because a have a few hundred lights later on). currently one light is selected with RGB of 4 4 4




{

$selected = `ls -sl`;

for( $node in $selected ) {

$colorR = `getAttr ($node + ".colorR")`;
$colorG = `getAttr ($node + ".colorG")`;
$colorB = `getAttr ($node + ".colorB")`;


print ( $colorR +" " );
print ( $colorG +" " );
print ( $colorB +"\n" );


CreateSpotLight;
//create new spotlight and paste above RGB values to it

$spot = `ls -sl`;
//guess this new selection list creates interfering problems with 1st selection list, but how else can I select these new items?

setAttr ($spot + "Shape.colorR") ($colorR);
setAttr ($spot + "Shape.colorG") ($colorG);
setAttr ($spot + "Shape.colorB") ($colorB);

}

print $selected;


};
4 4 4
defaultSpotLight(1, 1,1,1, 0, 40, 0, 0, 0, 0,0,0, 1, 0);
// Error: line 23: Cannot convert data of type string[] to type string. //



:confused:

NextDesign 22-03-2010 12:07 AM

The reason why that is happening, is because `ls -sl` returns an array of objects, not a single object. A nasty way to get around this, I say nasty as there are much "cleaner" ways to do it, but since you know that there will always be only one object in the selection list at a time, you can do this:

$spotList = `ls -sl`;
$spot = $spotList[0];

This will only use the first object in your selection array.

You will also get into trouble with your code to assign the colors to your spotlight. You can fix this by doing this:

setAttr ($spot + ".color") -type double3 $colorR $colorG $colorB;

Hope this help you out mate.

Falott 22-03-2010 06:43 AM

oh man! I wish my life was that easy sometimes. thx alot mate, worked perfectly fine.


All times are GMT. The time now is 10:42 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Simply Maya 2018