// procedure rmToFloor(int $pc) // Move the lowest point of all objects in the selection so they sit exactly on the // top of the grid (global Y=0). // // params: // int $pc - pivot control - (0 | 1 | 2) // 0 = maintain object space (relative) pivot position // 1 = maintain world space (global) pivot position // 2 = center the pivot // // usage: rmToFloor( 0 | 1 | 2); // Copy this script to your maya scripts folder and source it and then make a selection of all // the objects you want to move so they are sitting on the grid and enter the command // rmToFloor 0 | 1 | 2;. // // notes: //(1) This procedure depends on the mel command "exactWorldBoundingBox $obj" which // returns a float[] xmin ymin zmin xmax ymax zmax. I use ymin to temporarily set // the Y position of $obj's pivot so I can move it along Y such that it sits on the grid. // Moving each object to the grid has a constant complexity O(1). This procedure has a // complexity of O(n), where n is the number of objects in the selection. // // [strike](2) this procedure moves the object but leaves the objects pivot in the same worldspace // location. I am not sure of the value of doing this and may want to either keep the // local (relative) pivot location or just center the pivot. // // [strike](3) changed the script to maintain the relative pivot when the object is moved. // // (4) changed script to accept a pivot control parameter to control if the object object // space or world space pivot is maintained or if the pivot is simply centered. // // author: ctbram with valuable input from nextdesign // date: 05292012 // // change log: // 05292012 - // (1) changed the program so the relative pivot of the object is maintained rather // then the world pivot // (2) added $pc (pivot control) parameter to control how the pivot is handled when the // object is moved. 0 = maintain object space, 1 = maintain world space, 2 = center pivot // // 05302012 - // (1) Before computing the lower pivot using the bounding box I had to freetransformation // on each object to zero out the rotation and align the bounding box to the global axis. // Until I can find a better solution this is going to have to be lived with. // // (2) solved the freezetransform problem by simply executing an undo command after getting // the $lowest value. Only Commands are placed into the undo queue so exactWorldBoundingBox // is a function and is not queued. So once I have $lowest simply running undo, undoes the // FreeTransformation. // global proc rmToFloor(int $pc) { string $sel[] = `ls -sl`; string $obj; int $undoFlag = false; // keep track of toggling the undo queue // make sure the pivot control parameter is 0 | 1 | 2. if (!(($pc == 0) || ($pc == 1) || ($pc == 2))) error("pivot control parameter must be (0 | 1 | 2)."); for($obj in $sel) { float $osPivot[] = `xform -q -os -rp $obj`; // save the object space (relative) pivot float $wsPivot[] = `xform -q -ws -rp $obj`; // save world space $obj pivot // if the undo queue is off turn it on if (!(`undoInfo -q -st`)) { $undoFlag = true; undoInfo -st true; } select $obj; FreezeTransformations; // ensure the bounding box is not rotated float $bbox[] = `exactWorldBoundingBox $obj`; // get bounding box world space coords float $lowest = $bbox[1]; // get lowest vert (ymin) undo; // undo the FreezeTransformation command // if the undo queue was off, turn it back off if ($undoFlag) { $undoflag = false; undoInfo -st false; } xform -ws -rp $wsPivot[0] $lowest $wsPivot[2] $obj; // reset the pivot to the lowest point in world space move -rpr $wsPivot[0] 0 $wsPivot[2] $obj; // move the object to the grid // handle the pivot based on the pivot control parameter $pc if ($pc == 0) xform -os -rp $osPivot[0] $osPivot[1] $osPivot[2] $obj; // restore the object space (relative) pivot else if ($pc == 1) xform -ws -rp $wsPivot[0] $wsPivot[1] $wsPivot[2] $obj; // restore the world space (relative) pivot else xform -cp $obj; // center the pivot } select $sel; // retore the original selection }
That won't work if the vertices have been moved. Take a sphere, move the vertices up, then run your script. By moving the vertices, you never changed the transform node's attributes, so you script won't do anything. The script by Rick above looks at the bounding box of the vertices, so it knows how far to move the transform node to sit the object on the floor.move -ls 0 0 0;
rotate -a 0 0 0;
CenterPivot;
![]()