PDA

View Full Version : snapping objects to 000 grid


Saurus
08-22-2005, 07:21 PM
Any mel that will move an objects with a messed up translate to 000 grid? Dealing with objects that are a zillion miles from 000 and had use several steps to get objects back to center position.

Thanks!

AndersEgleus
08-23-2005, 08:35 AM
Do you mean messed up in a way that even if you set the object's translate to {0, 0, 0}, its geometry still ends up somewhere else?

Here's a procedure that will set the translate to where the pivot is without moving the object. It will only work on one object and it must not have any incoming connections to translate, rotate or scale. Plus it must not be parented to anything. You'll have to center the pivot yourself before running the procedure.

proc setTranslateToPivot ()
{
// get current selection
string $selection [] = `ls -tr -sl`;
// create a null at the origin
string $null = `group -em`;
// get the pivot of the object
float $pivot [] = `xform -query -worldSpace -rotatePivot $selection [0]`;
// move the null to the pivot of the object
xform -worldSpace -translation $pivot [0] $pivot [1] $pivot [2] $null;
// parent the null to the object
string $nullChild [] = `parent $null $selection [0]`;
// zero all transformation attributes on the null except translate so that
// it gets the same world space rotation and scale as the object
setAttr ($nullChild [0] + ".r") 0 0 0;
setAttr ($nullChild [0] + ".s") 1 1 1;
setAttr ($nullChild [0] + ".sh") 0 0 0;
// unparent the null
string $nullWorld [] = `parent -world $null`;
// parent the object to the null
string $objectChild [] = `parent $selection [0] $nullWorld [0]`;
// freeze transformations on the object
makeIdentity -apply true $objectChild [0];
// unparent the object
string $objectWorld [] = `parent -world $objectChild [0]`;
// reset the selection
select -replace $selection;
}
setTranslateToPivot;

azshall
08-26-2005, 06:38 PM
Any mel that will move an objects with a messed up translate to 000 grid? Dealing with objects that are a zillion miles from 000 and had use several steps to get objects back to center position.

Thanks!

i wrote a script that does this .. even if freeze transforms have been done... the script creates a null object or locator at the default 0 0 0 origin/world space. then point constrains t object to it ... and ten deletes the null and constraint ... forcing theo bject to the origin no matter where its at ... there is an option in the point constrain box or flag you need to turn off which is 'Maintain Offset' .. this will point constrain the object, but leave it where it is, ... Hope that helps, I unfortunately cannot give out the script due to my work restraints.

az

Saurus
08-26-2005, 07:12 PM
Thanks Guys! :)

CGTalk Moderation
08-26-2005, 07:12 PM
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.