Expressions - How to set attributes using string variables?

Expressions - How to set attributes using string variables?

dkrelina
Advocate Advocate
1,599 Views
2 Replies
Message 1 of 3

Expressions - How to set attributes using string variables?

dkrelina
Advocate
Advocate

Hi,

 

I'm trying to create an expression that sets the color of multiple materials using a loop. I would like to store the name of all the materials as an array of strings. How do I use a string variable to set an attribute, rather than hard-coding it?

 

For example...

 

$mat = 'lambert2';

lambert2.colorR = 0;      // This works
$mat.colorR = 0;          // This doesn't... How do I get it to work? How do I set an attribute?

 

Capture.PNG

0 Likes
Accepted solutions (1)
1,600 Views
2 Replies
Replies (2)
Message 2 of 3

mspeer
Consultant
Consultant

Hi!

 

$mat + ".colorR"

Message 3 of 3

dkrelina
Advocate
Advocate
Accepted solution

Thanks @mspeer. After doing a bit more research, this is what I was looking for...

 

$mat = "lambert2";
setAttr ($mat + ".colorR") 0;

 

0 Likes