Domanda

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

È stato utile?

Soluzione

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.

Altri suggerimenti

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 :)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top