Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Assets Free batch melscript export code for batching to FBX

Discussion in 'Works In Progress - Archive' started by SymbolSculptors, Apr 16, 2019.

  1. SymbolSculptors

    SymbolSculptors

    Joined:
    Jan 10, 2011
    Posts:
    7
    Hi!
    So I've just recently run into a problem where exporting models as a giant kit seems to work against the new prefab system (You cant seem to alt drag to quickly duplicate meshes anymore unless you unpack a prefab) so I wrote a quick mel utility to export everything into their seperate meshes, organized in their own folders!

    How it works: When you create an object in Maya - Name it with a Folder Name seperated with an underscore in the front - for example, Turret_Large1A will create a folder called Turret and put the Turret_Large1A mesh inside it.


    Code (mel):
    1. //Grab a list of everything selected.
    2. string $lsS[] = `ls -sl`;
    3. //Now create a loop to process the file export command.
    4. for ($i = 0; $i < `size ($lsS)`; $i ++)
    5. {
    6. select($lsS[$i]);
    7. //create the name to output. Don't forget to modify the pathfile
    8. string $buffer[];
    9. tokenize $lsS[$i] "_" $buffer ;
    10. //Insert your directory path here - just remember that instead of \ maya uses /
    11. string $dirBase = ("C:/Users/Someone/Desktop/SomeFolder/SomeModel/" + $buffer[0] + "/");
    12. sysFile -makeDir $dirBase;
    13. string $output = ($dirBase + $lsS[$i] + ".fbx" );
    14. //select the object and then export it
    15. select $lsS[$i];
    16. file -force -options "v=0;" -typ "FBX export" -pr -es $output;
    17. };
    This is written in MelScript for Maya users. (God damnit unity for making me organised)

    How to use: Drag it to your code window in melscript, select a few objects and run the code.


    ExportFolder.png
    how to use.png
    Result.png

    **Note the original mel code did come from somewhere on the unity forums, I just modified it (added in string tokenizing and exporting of groups)

    Original link here:
    https://forum.unity.com/threads/maya-export-many-objects-from-same-scene-as-differnt-files.139365/

    and how to use tokenize here:
    https://www.highend3d.com/maya/tutorials/scripting/mel/c/mel-scripting-tokenize-command
    Btw Im not entirely sure where code like this goes - so if its in the wrong place please move it :)