Put expression into multiple objects with script?

Put expression into multiple objects with script?

Anonymous
Not applicable
916 Views
3 Replies
Message 1 of 4

Put expression into multiple objects with script?

Anonymous
Not applicable
Hi bit of a noob question...
I'm trying to get to grips with MEL, I have an expression controlling the rotation of an object which I now want to use in 100+ other objects.
I need to write a script that will put this expression into all of the selected objects.
Does anyone know how do I do that? Any help greatly appreciated.
0 Likes
917 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Here's a very simple example:

string $sel[] = `ls -sl`;
for ($tmp in $sel) {
expression -s ($tmp + ".translateX=frame");
}
0 Likes
Message 3 of 4

Anonymous
Not applicable
Thanks very much for getting back to me. This works fine by itself but in my case I want to control several attributes, some of which depend on if/else statements?

This is a small part of the original expression. (I was thinking of posting the entire expression but its not exactly short.) I was testing it on a cube. hence pCube 1 is written everywhere.


if ($randA == 0)
{
pCube1.rotateX = $rotateX;
pCube1.rotateY = $rotateY;

}
else if ($randA == 1)
{
pCube1.rotateX = $rotateX;
pCube1.rotateZ = $rotateZ;
}


__________________________
This is what I changed it to.

if ($randA == 0)
{
expression -s ($tmp + ".rotateX = $rotateX");
expression -s ($tmp + ".rotateY = $rotateY");

}
else if ($randA == 1)
{
expression -s ($tmp + ".rotateX = $rotateX");
expression -s ($tmp + ".rotateZ = $rotateZ");
}

Basically I've replaced "pCube1" with the "expression -s ($tmp" etc
I also put this part at the begginning of the script.

string $sel[] = `ls -sl`;
for ($tmp in $sel) {


I'll say now that it didn't work with my expression. So I assume thats just because I've used the script incorrectly.

How would I go about integrating it?


Thanks.
0 Likes
Message 4 of 4

Anonymous
Not applicable
Success

I figured out what I was doing wrong.

This is the script that I used.


string $mySel[] = `ls -sl`;

for ($i=0; $i<size($mySel); $i++)
{
expression -s "The entire expression goes here" -o $mySel -ae 1 -uc all ;
}

What I done was create a cube. Go into the expression editor and asign my expresion to the cube. Then looked in the script editor to see what it generated. (in this case... expression -s "The expression I created" -o pCube1 -ae 1 -uc all 😉 I then Swapped pCube1 for $mySel and put the other bit of script in front. I realised that you cant put any returns in the expression of the script, and that you had to replace them with \r.

Thanks agian.
0 Likes