/* EJL_objXport 3-12-08 updated 5-12-08 updated 7-11-08 - added pivot and name retention updated 7-31-08 - added transform storage info, consequently stores pivot rotation info (very cool) A simple script that exports your selected mesh to your local disk, then deletes the mesh, and re-imports the OBJ as a method of providing a clean model. - now checks model to make sure it doesn't have non-manifold verts, edges or lamina faces which would prevent re-importing of OBJ */ global proc EJL_objXport() { string $sel[] = `ls -sl`; float $totalTime; int $count = 0; string $units; float $timex; float $mathresult; int $percent; int $selsize; int $numTokens; int $buffer[]; int $hours; int $minutes; int $seconds; // -----> Important: this is the path OBJs will be saved to string $path = "C:/temp/"; // start timer $startTime = `timerX`; // export selected geo as obj and reimport string $sel[] = `ls -sl`; print "\n==================================================================\n"; print "EJL_objXport Feedback:\n"; print "==================================================================\n"; for ($hello in $sel) { // get and store name of first model exported string $name = $hello; // store location in hiarchy string $nameParent = firstParentOf($name); // remove from hiarchy (unparent) script will be buggy if this doesn't happen if ($nameParent == "") { // do nothing, as it was not grouped under anything } else { select -r $hello; parent -a -w; } // store transform information! // float $xform_tx = `getAttr ($hello + ".translateX")`; // float $xform_ty = `getAttr ($hello + ".translateY")`; // float $xform_tz = `getAttr ($hello + ".translateZ")`; float $xform_rx = `getAttr ($hello + ".rotateX")`; float $xform_ry = `getAttr ($hello + ".rotateY")`; float $xform_rz = `getAttr ($hello + ".rotateZ")`; // float $xform_sx = `getAttr ($name + ".scaleX")`; // float $xform_sy = `getAttr ($name + ".scaleY")`; // float $xform_sz = `getAttr ($name + ".scaleZ")`; // change all transforms back to zero, since we have recorded the information. // setAttr ($hello + ".translateX") 0; // setAttr ($hello + ".translateY") 0; // setAttr ($hello + ".translateZ") 0; setAttr ($hello + ".rotateX") 0; setAttr ($hello + ".rotateY") 0; setAttr ($hello + ".rotateZ") 0; // setAttr ($name + ".scaleX") 1; // setAttr ($name + ".scaleY") 1; // setAttr ($name + ".scaleZ") 1; // store pivot information vector $sPivot = `xform -q -ws -rp $name`; float $pivot[] = $sPivot; // check for geometry problems prior to export for ($current in $sel) { string $lamina[] = `polyInfo -lf $current`; int $laminaCnt = `size $lamina`; string $nonman_verts[] = `polyInfo -nmv $current`; int $nonman_vertsCnt = `size $nonman_verts`; string $nonman_edges[] = `polyInfo -nme $current`; int $nonman_edgesCnt = `size $nonman_edges`; if ($laminaCnt != 0) { error ($current + " has lamina faces. Aborting..."); } if ($nonman_vertsCnt != 0) { error ($current + " has non-manifold verts. Aborting..."); } if ($nonman_edgesCnt != 0) { error ($current + " has non-manifold edges. Aborting..."); } } select -r $hello; file -op "groups=0;ptgroups=0;materials=0;smoothing=0;normals=0" -typ "OBJexport" -pr -es ($path + "tmp.obj"); select -r $hello; doDelete; // print "EJL Says: Objects have been exported to OBJ and deleted.\n"; // get list of current objects in scene string $topOrig[] = `ls -fl -as` ; // All top level assemblies // import operation string $newimport = `file -import -type "OBJ" -rpr "tmp" -options "mo=1" ($path + "tmp.obj")`; ////////// Renaming magic, courtesy of OBJLove Script // check scene again to get newly imported item name string $topNew[] = `ls -fl -as`; // And again so we can see what is NEW! int $cnt = 1 ; string $top ; for ($top in $topNew) { // See if this obj was already here before... int $old = 0 ; string $check ; for ($check in $topOrig) { if ($top == $check) // Yep skip it { $old = 1 ; break ; } } if ($old) continue ; string $tmpdup[] = `duplicate $top`; delete $top; // print "Duplicated and deleted newly imported OBJ\n"; // print ("// Renaming "+$top+" //\n") ; // It's new! Rename it and keep count! if ($cnt <= 1) { rename $tmpdup[0] $name ; select -r $name; CenterPivot; } else rename $tmpdup[0] ($name+$cnt) ; ++$cnt ; } ////////End of OBJ love script... // change pivot of new OBJ to original model's pivot... xform -ws -rp $pivot[0] $pivot[1] $pivot[2] $name; // reset normals to all soft, because it looks pretty that way polySoftEdge -a 180 $name; // redo transforms from what we recorded earlier // setAttr ($name + ".translateX") $pivot[0]; // setAttr ($name + ".translateY") $pivot[1]; // setAttr ($name + ".translateZ") $pivot[2]; setAttr ($name + ".rotateX") $xform_rx; setAttr ($name + ".rotateY") $xform_ry; setAttr ($name + ".rotateZ") $xform_rz; // setAttr ($name + ".scaleX") $xform_sx; // setAttr ($name + ".scaleY") $xform_sy; // setAttr ($name + ".scaleZ") $xform_sz; // put object back in it's original location within hiarchy if ($nameParent == "") { // do nothing, as it was not grouped under anything } else { parent $name $nameParent; } // get rid of history select -r $name; DeleteHistory; // increment counter $count = ($count + 1); // feedback $selsize = `size($sel)`; $mathresult = ($count * 100 / $selsize); $percent = $mathresult; print ( "EJL Says: Percent done = " + $percent + "% - Current object is " + $name + "\n" ); // end of loop } // stop timer $totalTime = `timerX -startTime $startTime`; /* // timer math if ($totalTime >= 60) { $units = "minutes"; $timex = ($totalTime / 60); $numTokens = `tokenize $timex "." $buffer`; $minutes = $buffer[0]; $seconds = ($buffer[1] * 60); } else if ($totalTime >= 3600) { $units = "hours"; $timex = ($totalTime / 3600); $numTokens = `tokenize $timex "." $buffer`; $hours = $buffer[0]; $minutes = ($buffer[1] * 60); } else { $units = "seconds"; $timex = $totalTime; // $seconds = $totalTime; } */ // reselect oringinally selected objects select -r $sel; print ("\nTotal number of objects: " + $count); print "\n==================================================================\n\n"; print ("EJL Says: I cleaned a total of " + $count + " objects, in " + $timex + " " + $units + ". See script editor for details.\n"); /// //if ($units == "seconds") { //print ("EJL Says: I cleaned a total of " + $count + " objects, in " + $seconds + " " + $units + ". See script editor for details.\n"); //} //else if ($units == "minutes") { //print ("EJL Says: I cleaned a total of " + $count + " objects, in " + $minutes + " minutes and " + $seconds + " " + $units + ". See script editor for details.\n"); //} //else /*if ($units == "hours")*/ { //print ("EJL Says: I cleaned a total of " + $count + " objects, in " + $hours + " hour(s) and " + $seconds + " " + $units + ". See script editor for details.\n"); //} // end proc }