SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.

Home / forum / Animation / Mel Scripts & Programming / getAttr and setAttr in an array
Register FAQ Members List Calendar Mark Forums Read

New Thread
 
Thread Tools
Old 21-03-2010, 10: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 04:35 PM.
Falott is offline   Reply With Quote
Old 22-03-2010, 12:07 AM   #2
NextDesign
Technical Director
 
NextDesign's Avatar
 
Join Date: Feb 2004
Posts: 2,988
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, 06: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
New Thread

« Previous Thread | Next Thread »

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

1 Month

$34

Month-to-month billing
$34/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
 
 

3 months

$87

Billing every 3 months
$29/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $5 per month or $15 in total compared to monthly billing with this package.

12 months

$288

Billing every 12 months
$24/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $10 per month or $120 in total compared to monthly billing with this package.

Your plan will automatically renew. You can cancel at any time via your PayPal account to avoid being charged again.

You can view the FAQ on our video plans here. You can contact us directly here. By clicking one of the buttons above, you agree to our Terms and Privacy Policy.