Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Basic MEL programming problem

Basic MEL programming problem

Anonymous
Not applicable
314 Views
1 Reply
Message 1 of 2

Basic MEL programming problem

Anonymous
Not applicable
My goal is this:
- manually create a cone and rotate it in X by 90, move it to Z by 1, and move the pivot point to the origin.
write a script to duplicate it 3 times, and rotate them 90 degrees, 180 degress and 270 degrees in Y

Heres the code I have to do that, the commented out part is just what it is trying to do.

For some reason, this only rotates like 1 or 2 of the cones and randomly. Does anyone see where my issue is?



polyCone;
setAttr pCone1.rx 90;
setAttr pCone1.tz 1;
move 0 0 0 pCone1.scalePivot pCone1.rotatePivot;

/*
set for loop to run for 3 turns
duplicate cone
select it based on $count number
rotate it by $count *90 so count 1 - rotate it 90, count 2 - rotate is 180 count 3 - rotate it 270.

*/

for ($count = 1; $count < 5; $count++)
{
duplicate pCone1;
select ("pCone" + $count);
rotate -r 0 ($count * 90) 0;
};
0 Likes
315 Views
1 Reply
Reply (1)
Message 2 of 2

lee.dunham
Collaborator
Collaborator
not sure i understand when you say only rotating 1 or 2 cones randomly, this script will not produce 'random' transformations.
Although, there are issues with it, your duplicating the first cone and giving each duplication the same transformation.
Another big issue is that your assuming no other node will have similar names, this can lead to many issues. instead of relying on names, store the results of creator functions into variables.

// set value of rotation to variable for easy adjusting
float $rotate = 90 ;
string $originalObject[] = `polyCone` ;
setAttr ( $originalObject + ".rx" ) $rotate ;
setAttr ( $originalObject + ".tz" ) 1 ;
move 0 0 0 ( $originalObject + ".scalePivot" ) ( $originalObject + ".rotatePivot" ) ;

for ($count = 0; $count < 3; $count++) {
// store name of duplicate into variable
string $duplicateObj[] = `duplicate $originalObject` ;
// rotate duplicate by value of rotation * count (+1 because it starts at 0)
rotate -r 0 ( $rotate *( $count +1 ) ) 0 $duplicateObj ;
}
0 Likes