Maya MEL exporter part 2

I made some changes to my MEL OBJ exporter so it exports the selected objects one by one, feel free to copy it from below, credits to Rob The Bloke for his MEL script examples on his website and to Jon Macey for hosting it. (Lucky enough to have a guest lecture from Rob recently, he really knows his stuff!)


Anyway here is the script feel free to copy: (and let me know if it could be better)

// Adapted from:

// This procedure is called when the 'Open' button of the dialog is clicked.
// The procedure recieves the name of the file and it's extension
proc int onOk(string $dirpath,string $type) 
   string $path;
   string $name;
   $path = ($dirpath + "/");
   print("Path Set To: "+$path+"\n");
   // create a prompt dialog to request the users name
		    string $nameList[] = `ls -selection -long`;
		    select -cl  ;
            for($object in $nameList)
                select -r $object;
                xform -cp;
    		    string $result = `promptDialog 
    			-title "Name The Asset: "
    			-message ("Enter Name: (" + $object + ")")
    			-button "OK" -button "Cancel"
    			-defaultButton "OK" -cancelButton "Cancel"
    			-dismissString "Cancel"`;
        	 	// if OK pressed
        		if ($result == "OK") {
                        // query the entry typed by the user
        			    $name = `promptDialog -query -text`;
        			    print("Exporting: " + $path + $name + "\n");
                        float $x = getAttr($object+".tx");
                        float $y = getAttr($object+".ty");
                        float $z = getAttr($object+".tz");
                        move -xyz -rpr 0.0 0.0 0.0 $object;
                        rotate -r -os -fo 90 0 0 ;
                        file -force -options "groups=1;ptgroups=0;materials=0;smoothing=1;normals=1" -type "OBJexport" -pr -es ($path + $name);
                        move -xyz $x $y $z $object;
                        rotate -r -os -fo -90 0 0 ;
        		else {
        			print("Export Canceled\n");
   return true;

// The final parameter indicates the type of file dialog. 4=Folder Dialog
// The 1st parameter is a function to call when OK is pressed.
// The 2nd parameter is the text to appear on the OK button.
// The 3rd parameter is the type of file, somewhat meaningless here
fileBrowser( "onOk", "Text", "", 4 );

Leave a Reply

Your email address will not be published. Required fields are marked *