View Full Version : snapping pivot points problems

Matt Leishman
05 May 2003, 04:20 PM
ok everyone, I'm really showing off my inexperience and "noob"ness with MEL scripting here (I'm just learning, and teaching myself isn't always a clean process :) ), but any help anyone can give with this little script I'm trying to write is really appreciated.

This script has probably already been written by someone, but I couldn't find it, and its something I do alot of in character rigging, so I figured it would be a good tool to start with in my early beginnings of learning MEL.

The idea behind it is that I'd like to snap the pivot point of one object to the pivot point of another object. Yes, I realize that this is a rather quick thing to do in Maya manually, but I do it so much that having a hotkey, or shelf button to speed it up would be great in the long run.

How I thought it could work is that first you would pick the object whose pivot you would like to snap somewhere, and then pick the object whose pivot you are snapping the previous pivot to. Then run the mel script and the first object's pivot snaps to the second objects pivot point. here is what I have so far:

// get a list of the selected objects
string $selected[0];
$selected = `ls -sl`;
//find out the pivot point of the second selected object
vector $pivot = `xform -q -piv $selected[1]`;
//move pivot of object 1 to pivot of object 2
move $pivot $selected[0].scalePivot $selected[0].rotatePivot;

Looking at it, it makes sense to me, but obviously i'm not getting it to work properly. I just don't know enough. Any direction any of you guru's can give would be awsome. Thanks for your time.

05 May 2003, 04:51 PM
you can do that with xform as well.......

i usually use a float array for the positions of other objects, but i would do this

float $Pos[] = `xform -q -ws TargetObject`

xform -ws -piv $Pos[0] $Pos[1] $Pos[2] baseObject;

xform will move the pivot point as well, as long as it isnt in query al you have to do is remove the -q flag

hope this helps,


Matt Leishman
05 May 2003, 05:10 PM
sweet, thanks sedric. Is there a way to make the script work when both of the objects have had their transforms frozen? the script didn't work when they were frozen, but it did work when they weren't frozen. Big help man, thanks for your help so far.

Matt Leishman
05 May 2003, 05:52 PM
nevermind, its all good. I figured something out. Big help sedric, thanks!!


05 May 2003, 06:04 PM
im glad it worked......anything to help a fellow Calgarian!!

cya around,


CGTalk Moderation
01 January 2006, 06:00 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.