MEL - Move Object's Pivot

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  03 March 2011
MEL - Move Object's Pivot

Hello folks,

I have 5 objects, which are rotated into different X direction. I would like to move the pivot of every object to its bottom. But through MEL how to find the exact bottom middle position of all given objects?

Someone please help me to find it out.

Thanks in advance.
 
  03 March 2011
Loop through objects and query bounding box. Do some simple math to average out the x and z .
 
  03 March 2011
Do you mean move the pivot of each individual object to that object's bottom center or to virtual center of all objects combined (basically an average of their positions)?

For the first case (each object's pivot individually):

$mySelection = `ls -sl -type "transform"`;
string $obj;

for ($obj in $mySelection) {
    
    float $BBox[] = `xform -q -ws -bb $obj`;        // get the bounding box info
    
    xform -ws -p true -cp $obj;        // center pivot
    
    float $centerPos[] = `xform -q -ws -sp $obj`;
    
    xform -ws -piv $centerPos[0] $BBox[1] $centerPos[2] $obj;    //move Pivot to bottom, but keep in center
}



For the second option, use this code. NOTE: it will mess with your hiearchy, if you have previously grouped the objects into a custom hierarchy. All selected objects will end up parented to the World. But it's just a proof of concept, modify to suit your needs:

$mySelection = `ls -sl -type "transform"`;
string $obj;
// temporarily group objects for convenience
group -n "pivotTempGrp" -w $mySelection;

// query average center of objects and BoundingBox for minY (lowest point in Y)
float $objCenter[] = `objectCenter pivotTempGrp`;
float $objBB[] = `xform -q -ws -bb pivotTempGrp`;

// set the pivot for each object accordingly to centerX, minY, centerZ
for ($obj in $mySelection) {

    xform -ws -piv $objCenter[0] $objBB[1] $objCenter[2] $obj;
}

// delete temporary group
ungroup pivotTempGrp;


The code above will determine the center of all objects combined in X and Z and the lowest point on Y (basically, the very bottom of the lowest object in the selection). All values in Worldspace for convenience.

Last edited by Nyro : 03 March 2011 at 05:32 PM.
 
  03 March 2011
Nyro, thanks mate. I need to get the first method to be done.

I think my objects are moved in Object Space, I will check it. For new objects it works perfectly.

Last edited by cppgraphics : 03 March 2011 at 02:23 AM.
 
  03 March 2011
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 07:36 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.