Maya Training

Introduction to Hard Surface Modeling

Maya Training

Interiors and Furniture Vol 1 & 2 - Modeling & Cloth

Maya Training

Shading, Lighting and Rendering the Bedroom in MR

Maya Training

Robot volume one - Modeling with animation in mind

Maya Training

Spach-Alspaugh House the complete courseware

Maya Training

Burt The Cartoon Dinosaur Vol 01 - Modeling

New Maya Training

Robot Volume 02 - Hybrid Rigging
You are here > Home > SimplyMaya Community Forums
Loading

Welcome to Simply Maya

Please Sign in or Sign up for an account

Member Login

Lost your password?

Not a member yet? Sign Up!

Old 21-03-2010, 11:19 AM   #1
Falott
Registered User
 
Falott's Avatar
 
Join Date: Jan 2005
Location: vienna
Posts: 1,095
Thanks: 3
Thanked 20 Times in 18 Posts
Default 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. //



__________________
everything starts and ends in the right place at the right time.

Last edited by Falott : 21-03-2010 at 05:35 PM.
Falott is offline   Reply With Quote
Old 22-03-2010, 01:07 AM   #2
NextDesign
Technical Director
 
NextDesign's Avatar
 
Join Date: Feb 2004
Posts: 2,982
Thanks: 33
Thanked 532 Times in 471 Posts
Default

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.
__________________
Imagination is more important than knowledge.
NextDesign is offline   Reply With Quote
Old 22-03-2010, 07:43 AM   #3
Falott
Registered User
 
Falott's Avatar
 
Join Date: Jan 2005
Location: vienna
Posts: 1,095
Thanks: 3
Thanked 20 Times in 18 Posts
Default

oh man! I wish my life was that easy sometimes. thx alot mate, worked perfectly fine.
__________________
everything starts and ends in the right place at the right time.
Falott is offline   Reply With Quote

A little bit about who we are
Links you might find useful
Catch up with SimplyMaya
SimplyMaya specialises in Maya tutorials. We offer over 1,000 individual Maya training videos, ranging from basic Maya tutorials through to intermediate Maya tutorials. Our tutorials are created by instructors with industry experience and are designed to get you up and running in Maya quickly without making it seem like hard work.

Copyright © 1999-2015 SimplyMaya - vBulletin® Copyright © 2000-2015, Jelsoft Enterprises Ltd.