this is as close as I have got...doesnt work tho:that would be a handy one alright..
string $sel[] = `ls -sl`; string $obj; for ($obj in $sel) { setAttr ($obj + ".translateX") 0; setAttr ($obj + ".translateY") 0; setAttr ($obj + ".translateZ") 0; }
// procedure: centerObjects() // usage: centerObject(); // author: ctbram // date: 05272012 // // Place this script into your maya folders scripts folder and name it // "centerObjects.mel" and then use by selecting objects that you want // to center pivot and move to the global origin ( 0 0 0 ) and then // enter the command "centerObjects();" on the command line. // // Not sure how useful this is as you can achieve the same thing by // selecting objects and then just setting their x,y,z coordinates to // zero in the channel box. But here is how to do it programatically. global proc centerObjects() { string $sel[] = `ls -sl`; string $obj; for ($obj in $sel) { // center $obj's pivot xform -cp $obj; // move $obj to the global origin (0,0,0) setAttr ($obj + ".translateX") 0; setAttr ($obj + ".translateY") 0; setAttr ($obj + ".translateZ") 0; } }
why? number 1..I want to learn Melscripting, this is a good place to start...and number 2, I want to move multiple objects with the click of a button, no typing on the keyboarderr yeah I agree with Dom....why cant you just type 0 for each in the translates??
J
// procedure: rmCenterObjects() // usage: rmCenterObjecst(0|1); // author: ctbram // date: 05272012 // // Place this script into your maya folders scripts folder and use by // selecting objects that you want to center pivot and move to the // global origin ( 0 0 0 ). // // examples: // 1. rmCenterObjects(0) moves the selected objects to the global origin while // 2. rmCenterObjects(1) moves the selected objects to the global origin and // freezes the objects transforms // // alternatively you can drop the parenthesis and use the format... // // rmCenterObjects 0; or rmCenterObjects 1; // // modified 05282012 // added the $ft flag // use the move command rather then setAttr to account // for objects that have had their transforms frozen global proc rmCenterObjects(int $ft) { string $sel[] = `ls -sl`; string $obj; // center each objects pivot, move it to the global origin and if // the $ft parameter is 1 then freeze its transforms... for ($obj in $sel) { // center $obj's pivot xform -cp $obj; // move the $obj to the global origin using move // relative to the rotation pivot -rpr move -rpr 0 0 0 $obj; // if $ft is 1 then freeze transforms after moving // $obj to theglobal origin if ($ft == 1) { select -r $obj ; FreezeTransformations; makeIdentity -apply true -t 1 -r 1 -s 1 -n 0; } } // restore the original selection select -r $sel; }
lol..why are you guys feeling so strongly about typing 0? sometimes it's nice to have buttons which do stuff, with no need to touch the keyboard..this is a good place to start..basics of a function...translations..now Im going to try a drop to floor script
C.