MEL – grid-centered OBJ-Exporter

Heyhey,

a new script is available. If you need to export all objects centered on the grid but on the other hand still want to keep the objects placed correctly in your scene your now good to go.

This little script allow you to export all single objects as separate .obj-files in one run (like a batch run) ūüėÄ
Never select and export object object per object per object…. AGAIN!

  1. First run the MEL script by hitting STRG+Enter with all the code selected. It will opens this window:
  2. As it says, please follow the instruction and save your scene somewhere on your PC (you may already did so while your creating assets anyway. If you already did so you can ignore this step)
  3. Select only the assets you want to export as .obj files. You can either directly select items in the scene or from a list (may be better for huge scenes):
  4. May it make sense for you to group all your objects like they are as a group
  5. Your assets will be exported in a new Folder in the directory were your scene is saved
  6. as a group:
  7. or single pieces:
  8. CTRL+Z will bring all objects back to original position – no need to reload the entire scene.

 

Hope that will be useful for you, too ♥

Cheers!

 

 

 

 

 

OBJ Exporter Script:



// Center item on grid Proc
//——————–
global proc centerItem()
{
CenterPivot;
move -rpr 0 0 0;
}

//centerItem();
//Freeze tranform Proc
//——————–
global proc resetItem()
{
FreezeTransformations;
DeleteHistory;
}

//resetItem();
//Group Export Proc
//——————–
global proc groupExport()
{
doGroup 0 1 1;
}

//Export Proc
//——————–
global proc exportSelection()
{
string $mySelection[] = `ls -sl`;
string $itemName;
for($itemName in $mySelection)
for ($n=0 ; $n < size($mySelection) ; $n++)
{
select -r $mySelection[$n];
//______________________________
$currentFilePath = dirname(`file -q -sceneName`);
$objfolder = $currentFilePath + “/OBJ_item_exporter__FILES__HERE/”;
sysFile -makeDir $objfolder;
string $objpath = ($objfolder + $itemName + “.obj”);
print $objpath;
file -force -options “(groups=1;ptgroups=1;materials=1;smoothing=1;normals=1”
-typ “OBJexport” -pr -es ($objfolder + $itemName + “.obj”);
//backup export to specific filepath
/*file -force -options “(groups=1;ptgroups=1;materials=1;smoothing=1;normals=1”
-typ “OBJexport” -pr
-es (“C:/Users/Susi/Desktop/test_export/” + $itemName + “.obj”);
*/}
}
//Checkbox Actions Proc
//——————–
proc makeObj()
{
if (`checkBoxGrp -q -value1 myChkBxGrp`) centerItem;
if (`checkBoxGrp -q -value2 myChkBxGrp`) resetItem;
if (`checkBoxGrp -q -value3 myChkBxGrp`) groupExport;
exportSelection;
}
//————————————————–
// Select items through Outliner Window Proc
//————————————————–
global proc outlinerSelection()
{
if (`window -ex selectionWindow` != true)
{
//Create a PolyCube (with renaming)and Look 4 show selected types in outliner
//polyCube -sx 1 -sy 1 -sz 1 -name “pCubeTest”;
lsThroughFilter -na DefaultGeometryFilter -sort byName -reverse false;

//Get the sorted Outliner Window

$selectionWin = `window -title “select objects” -wh 300 600 selectionWindow`;
frameLayout -labelVisible true;
string $panel = `outlinerPanel`;
string $outliner = `outlinerPanel -query -outlinerEditor $panel`;
//Delete upper created pcube to avoid getting an emtpy list in case there in no geometry in scene
//Delete pCubeTest;
outlinerEditor -edit
-autoExpand false
-showDagOnly false
-setFilter DefaultGeometryFilter
$outliner;
button -label ” |[ > export selected items < ]| ” -command makeObj;
button -label “cancel” -command (“deleteUI -control selectionWindow”);
showWindow $selectionWin;
}
}

//exportSelection();
//Window Proc
//——————–
if (`window -exists mainWindow`) deleteUI -window mainWindow;
{
$mainWindow = `window -title “OBJ item exporter” -widthHeight 400 700 -s false mainWindow`;
formLayout -numberOfDivisions 7 myForm;
string $infoText1 = `text (“Please SAVE your SCENE before you start to export.”)`;
string $infoText2 = `text (“All objects will be exportet to this path”)`;
checkBoxGrp
-numberOfCheckBoxes 3
-columnWidth3 120 120 120
//-label “select type”
-labelArray3 “center to grid” “freeze transforms” “export as group”
myChkBxGrp;
separator;
button -label ” |[ > export selected items < ]| ” -command “makeObj()” myBtn1;
button -label ” select from list ” -command “outlinerSelection()” myBtn2;
string $infoText3 = `text (“¬© Powered by Susann Baumgart”)`;

formLayout -edit
-attachForm $infoText1 “left” 10
-attachForm $infoText1 “top” 0
-attachForm $infoText2 “left” 10
-attachForm $infoText2 “top” 12
-attachForm myChkBxGrp “left” 10
-attachForm myChkBxGrp “top” 35
-attachForm myBtn2 “left” 140
-attachForm myBtn2 “top” 65
-attachForm myBtn1 “left” 100
-attachForm myBtn1 “top” 90
-attachForm $infoText3 “left” 110
-attachForm $infoText3 “top” 120
myForm;
showWindow $mainWindow;
}

 

 


Core Proc:


global proc exportSelection()
{
string $mySelection[] = `ls -sl`;
string $itemName;
for($itemName in $mySelection)
for ($n=0 ; $n < size($mySelection) ; $n++)
{
select -r $mySelection[$n];
CenterPivot;
FreezeTransformations;
DeleteHistory;
move -rpr 0 0 0;
FreezeTransformations;
//______________________________
file -force -options “(groups=1;ptgroups=1;materials=1;smoothing=1;normals=1”
-typ “OBJexport” -pr
-es (“C:/Users/sbaumgart/Desktop/test_export/” + $itemName + “.obj”);
}

}

exportSelection();

Leave a Comment

Your email address will not be published.