PDA

View Full Version : proc> move to position of the end joint?


jgibz
09-19-2005, 08:49 PM
Hi everyone,
I have this simple procedure that moves one object to the position of another. The script works if you have just that--2 objects (like two spheres, etc.) But I want to use the script to move the the top joint in one joint chain to the very bottom joint in another chain.

like so:
http://www.unm.edu/~jgibz/joints.gif (http://www.unm.edu/%7Ejgibz/joints.gif)

When I try to run the script passing the two joints' names in strings I get:
http://www.unm.edu/~jgibz/afterProcedure.gif (http://www.unm.edu/%7Ejgibz/afterProcedure.gif)

Here's the code

proc jgMoveToObject(string $moved, string $to)
{
vector $positionTo = `getAttr ($to + ".translate")`;

select $moved;

move ($positionTo.x) ($positionTo.y) ($positionTo.z);

select -cl;
}


Any help would be great.

harmless
09-19-2005, 09:10 PM
It works properly in my test case. You may have to post a scene...

jgibz
09-19-2005, 09:31 PM
Alright, http://www.unm.edu/~jgibz/testScene.ma

john_homer
09-19-2005, 09:35 PM
I generally just use...
delete `parentConstraint "object1" "object2"`;

that way it get worldSpace not local (sortOf) like getAttr

.j

jgibz
09-20-2005, 12:09 AM
proc jgMoveToObject(string $moved, string $to)
{
delete `parentConstraint $to $moved`;
select $moved;
rotate 0 0 0; //this gets rotated in the y axis after it's moved.
}

Thanks john, this did it, but how on earth does this work?:)

EDIT* http://localhost:4446/Maya6.0/en_US/index.html?MEL Ahhhh.

john_homer
09-20-2005, 01:21 AM
a parent constraint with no options set does not maintain offset... so it basically aligns

so the command `parentConstraint` creates a parentConstraint between the 2 objects thus moving it.

as with all mel, when you create anything it returns the result, and this can be stored in a variable...
ie.
string $newPC[] = `parentConstraint`;

you can then edit/delete/whatever you want the constraint as its name is in the variable..

ie
delete $newPC[0];

I just skipped this step by deleting the result of the constraint command..

essentially the line says.. "delete (create a constraint)" so it creates it so it can delete it ;^)

hope that makes sence, its sorta hard to word..

.j

jgibz
09-20-2005, 05:48 AM
makes perfect sence, thanks a bunch.

jgibz
11-25-2005, 10:08 PM
I've been working on another script, and I want to move a node, say a locator, to the posiition of a vertice.


proc jgMoveToObject(string $moved, string $to)
{
vector $positionTo = `getAttr ($to + ".translate")`;

select $moved;

move ($positionTo.x) ($positionTo.y) ($positionTo.z);

select -cl;
}


Similair to the above code, I'm using


global proc jgCenterVerts()
{
string $verts[] = `ls -sl`;
string $vert;
vector $vertPos;
vector $locPos;

spaceLocator -p 0 0 0;
rename "jgLoc";

for($vert in $verts)
{
$vertPos = `getAttr $vert`;

select jgLoc;

move ($vertPos.x) ($vertPos.y) ($vertPos.z);
}

}



I'm having the same problems here as shown in the two pics above, this time the locator and the vert, like the two joints, dont lie in the same position. The fix suggested by John_homer worked for the joints, but not for the locator and vertice.

Does anyone have any ideas?

jgibz
11-26-2005, 02:13 PM
While reading some of the other posts here I found <pointPosition> This works, if anyone out there cares :)

Stucky
11-26-2005, 09:50 PM
Hey dude. I read very quickly your thread, cause I havent got much time right now, but what I understand is that you want to move an "object", in this last case is an object to the place of a vertex. well, I made a little script for that. It is in Highend3D.com you can grab it here (http://www.highend3d.com/maya/downloads/mel_scripts/utility_external/misc/3731.html). If I understood your problem uncorrectly I'm sorry for that, but i'm in a little rush. In the script, I used the xform command, and I move the objects in World Space, not in local space. Check it out if you like. This script only works with objects, not with components. Hope it helps :)

If you need help in this vertex case, PM me, cause I may forget to check this thread again..hehe...sorry for that...Although, you have to somehow enter component mode, and then check what vertex is selected, and then move the object to the place of the vertex.

-S

jgibz
11-26-2005, 11:35 PM
Hey Stucky,
Thanks for the reply, I'll check your script out, as for my problem, it's okay i figured out a solution(see above).

Stucky
11-27-2005, 01:24 AM
ok dude. sorry for reading your post so quickly, and didnt notice that yu already had the answer. but check my script, its always good to see other people achieve the same goals.
;)

CGTalk Moderation
11-27-2005, 01:24 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.