0

Hi I am a new MEL user and have been playing around , searching around but can't figure this out:

I was trying to move all the joint transform rotation values to the joint orient values so that i can clean up the attributes of the transforms without losing joint orientation, my mel attempt for it was this:


string $joints[]=`ls -type "joint"`;

//print($joints);

int $jnt_count = size($joints);

for ($i = 0; $i <= $jnt_count; $i++)

{

    int $attr1 = `getAttr $joints[i].rotateX`;
    int $attr2 = `getAttr $joints[i].rotateY`;
    int $attr3 = `getAttr $joints[i].rotateZ`;

    setAttr $joints[i].jointOrientX $attr1;
    setAttr $joints[i].jointOrientY $attr2;
    setAttr $joints[i].jointOrientZ $attr3;
}

I was hoping with the array of all the joints (names), i could change their attributes in that manner by calling to them one by one, but it seems I cannot do it that way

However! When I do an objectType $joints[1] to test, it still return a type "joints" , so I don't get why the value of the array is type joints, but I can't access the joint's joint.XXX attributes, can someone enlighten me on this matter or point me in the right direction?

Must appreciated!

Dave

Wooble
  • 87,717
  • 12
  • 108
  • 131
the pillow
  • 412
  • 6
  • 14
  • Your title made me chuckle :) Mel stands for Maya embedded language, so you're effectively writing Maya Maya embedded language :D – Shannon Hochkins Sep 27 '13 at 00:00
  • Sorry :D , I just felt it might be more clear if i start with maya, in case m.e.l might be something else somewhere else! – the pillow Sep 28 '13 at 02:46

2 Answers2

2

In mel you only ever get strings, floats or integers to work with - they are the names of objects in the scene, but not wrappers or handles to the objects themselves.

In your specific example, you'd want this:

string $joints[]=`ls -type "joint"`;

int $jnt_count = size($joints);

for ($i = 0; $i <= $jnt_count; $i++)

{

     float $attr1 = `getAttr ($joints[$i] + ".rotateX")`;
     // etc. See how this is done by adding the strings to 
     // create the string "youJointHere.rotateX", periods and all...
     // the parens make sure string is composed before the command is called

     setAttr ($joints[$i] + ".jointOrientX") $attr1;
     // etc.  Same trick
}

If you're new to this, you can save yourself a world of hurt and jumping straight to maya Python -- it's a lot more powerful than mel. The optional Pymel makes it even easier - the original code you posted is more or less what Pymel lets you do.

EDIT: forgot the $ variable identifier and parens in the first version.

Community
  • 1
  • 1
theodox
  • 12,028
  • 3
  • 23
  • 36
  • Hi, thanks for your response, when I tried it in that way I got an error saying: "Error: Line ..: Invalid use of Maya object "i"" for all the "i" being used in the for loop, so i thought it was because of the same string issue and tried the following: int $attr1 = `getAttr $joints + "[" + $i + "]" + ".rotateX"` and int $attr1 = `getAttr $joints + "[" + i + "]" + ".rotateX"` but both of them doesn't work, do you know what the problem may be? I will try to look into learning python as well! – the pillow Sep 25 '13 at 03:31
  • Python is a lot more powerfull at shooting oneself in the leg. Mel is good because of the echo facility and limitations, but taht's about it. Yes you read right limitations are a BIG part of why mel is so good. – joojaa Sep 25 '13 at 16:27
0

As theodox pointed out, Pymel makes this much easier! And is closer to your post.

joints = pm.ls(sl=1, type='joints')
jountCount = len(joints)
for i in range(jointCount):
    rot = joints[i].r.get()
    joints[i].jointOrient.set([rot[0], rot[1], rot[2]])

In my opinion, Pymel is much more superior, as it's easier to read, easier to write and derived from the api as mel is, it performs just as fast :)

Shannon Hochkins
  • 11,763
  • 15
  • 62
  • 95