Home Coding, Scripting, Shaders

[MEL Script] Batch FBX Exporter

1
polycounter lvl 14
Offline / Send Message
haiddasalami polycounter lvl 14
Hopefully this is useful to people exporting stuff out to UDK from Maya. You can batch export your models which take the geometry name. Currently trying to figure out an elegant solution to renaming/checking again if name is correct. So make sure to name your objects otherwise you are gonna get pSphere9000 :P Anywho here it is.

Download Here.

Installation:
1. Download the .mel file.
2. Place it in your My Documents/maya/scripts folder.
3. Re-start Maya (or type rehash in command line) and type fbxExporter; in the MEL command line to launch the tool.
4. Make shelf button or add to marking menu's for profit.

TO DO:
- Implement ASE batch export
- Implement quick pivot changes as second tab.
- Implement some sort of quick export options like recently used paths/last used options.

Cheers and feedback is always appreciated

EDIT: O and big thanks to MoP. Used his multiObjTool script to learn. Thanks MoP

Replies

  • MoP
    Offline / Send Message
    MoP polycounter lvl 18
    Hey haiddasalami! Cool idea, this is definitely useful for working with UDK. :)

    One thing I might suggest is that you investigate Sets with custom attributes on them (eg. export path) so that if the user exports a selection of multiple objects to a specific path/filename, you then store those objects in a new Set, name the Set to match the filename, and store the path in a custom attribute.

    You could also use Locators in sets to allow users to set custom pivot points for export - then the script can simply offset the contents of the Set to make the Locator be at world 0,0,0, resulting in a nicely aligned set of objects in a single FBX file.

    This'll mean you can have scenes containing multiple objects in any heirarchy, all being exported to custom FBX files with any offset or any sub-grouping of objects, which is much more flexible than simply outputting each object to its own filename.

    ... hmm, I should probably get around to upgrading my old scripts :)

    Keep up the good work, I'm sure a lot of people will find this handy, and no doubt have other good ideas to improve it too! :)
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Thanks MoP for the info. Definitely gonna look into sets.
  • jderiggi
    Offline / Send Message
    jderiggi polycounter lvl 9
    Thanks so much for the useful tool. Did you happen to work out how to keep the object's original location in world space upon exporting? Thanks again.
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    jderiggi wrote: »
    Thanks so much for the useful tool. Did you happen to work out how to keep the object's original location in world space upon exporting? Thanks again.

    No problem. Ill get that in by end of this week/today. Been working away/learning pymel for my next tool. Let me know if you have any suggestions!
  • Lamont
    Offline / Send Message
    Lamont polycounter lvl 15
    Awesome :D!! Mind if I mess with it? I'll post any working results.
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Lamont wrote: »
    Awesome :D!! Mind if I mess with it? I'll post any working results.

    Feel free too :) Also got the script updated to move back to its original location. Updated the original post with download too. Also looking back at the code, center pivot unchecked never worked haha so fixed that too.
  • Lamont
    Offline / Send Message
    Lamont polycounter lvl 15
    Last used options are - optionVar.
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Lamont wrote: »
    Last used options are - optionVar.

    thanks Lamont. Seen a bunch of scripts that do it that way. Gonna try and re-write this script with set functionality like MoP suggested and move this to python and maybe learn some pyQT along the way. Let me know what you cook up with it :)
  • Lamont
    Offline / Send Message
    Lamont polycounter lvl 15
    I did some digging on what MoP said about custom pivots. I think if you do export scene (maybe not object) while the objects are in a group it will retain the proper offset (world/local). Use the pivot for the group center.

    Just a thought.
  • S2Engine
    Offline / Send Message
    S2Engine polycounter lvl 10
    Very cool, I can see this being very useful in the near future :)

    One thing I'm interested in, and not sure how you would go about this, is some kind of system for exporting objects with collisions as well. I'd guess something like taking a mesh's name and allowing an option for user-input prefixes to get exported with it, like UCX_ or whatnot.
  • Lamont
    Offline / Send Message
    Lamont polycounter lvl 15
    I have my UCX rename script I can toss in, then you can mod how you need. I just updated it to do just simple rename as well. Need to update my random select as well.
    global proc UCXnameUI()
    {
    string $window = `window -title "UCXNamer v.0.9"`;
    string $meshName;
    string $meshSuf;
    string $meshLetter;
    rowColumnLayout -numberOfColumns 2 -columnAttach 1 "right" 0
        -columnWidth 1 100 -columnWidth 2 250;
    //text -label "Name" ObjectNM;
    text -l "Object Name" -al "left";
    textField -text $meshName ObjectNM;
    text -l "Suffix" -al "left";
    textField -text $meshSuf ObjectSUF;
    text -l "Prefix" -al "left";
    textField -text $meshLetter ObjectPRE;
    button -label "Rename" -command "nameUCX";
    //button -label "Rename" -command "nameUCX";
    showWindow $window;
    }
    UCXnameUI();
    
    
    global proc nameUCX()
    {
    $meshName = `textField -q -tx ObjectNM`;
    $meshSuf = `textField -q -tx ObjectSUF`;
    $meshLetter = `textField -q -tx ObjectPRE`;
    
    
    	string $sel[] = `ls -sl`;
    	string $curSel;
    	int $i = 1;
    
    	for( $curSel in $sel )
    	{
    		string $col = ($meshLetter + $meshName + "_" + $i);
    		print( $col + "\n");
    		string $curSelShapes[] = `listRelatives  -shapes $curSel`;
    		rename $curSelShapes[0] ($col + "_"+ $meshSuf);
    		rename $curSel $col;
    		$i++;
    	}
    
    }
    
  • Froyok
    Offline / Send Message
    Froyok greentooth
    First, thank you so much for this awesome script !
    I'm gonna use it everytime now ! :)

    Some questions/suggestions :

    -What does mean "Preserve Mesh Input Connections" ?

    -It's possible to get a message box error when you hit "export" without tipping before an output path ? I know, it's stupid, but sometimes I forgot and *bam*, I got a Maya crash. :poly142:

    -Does this exporter support the LODs ? Like explained on this UDN page : http://udn.epicgames.com/Three/FBXStaticMeshPipeline.html#Static%20Mesh%20LODs ?

    -It's also possible to export the full scene if when don't select anything ?

    [EDIT]
    I guess, something like that :
    if ($sizeSel == 0){
            warning("Nothing is selected");
            confirmDialog -title "Error" -message "Nothing is selected" -button "OK" -defaultButton "OK" -cancelButton "CANCEL";
        }
        else if( $sourcePath == "")
        {
            warning("No output path defined");
            confirmDialog -title "Error" -message "No output path is currently defined" -button "OK" -defaultButton "OK" -cancelButton "CANCEL";
        }
    

    But I don't get the message, only an error in the comment line of the maya window :
    "//Error: Cannot find procedure "fbxExport()"."
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Good to see people getting a use out of this :)

    @Froyok: Thanks for bringing those errors up. I swear I thought i put in checks but probably removed them at some point. Will fix those up today. Regarding preserve mesh input connections, if something is grouped, the fbx exporter will export that group as one mesh.

    LOD's should be doable. They just need an option ticked, which reminds me, anyone have any experience exporting animation with FBX? Do you just tick the animation box when exporting it or is there something else too? Regarding the full scene export, is there a functionality you want when nothing is selected?

    @S2Engine: Trying to think of a friendly way to integrate collision export as well. MoP's set method would probably be my best bet.

    @Lamont: thanks for that UCX code, will probably use it/tweak it to get what I need.

    Guess I have a lot of coding to do haha :)
  • S2Engine
    Offline / Send Message
    S2Engine polycounter lvl 10
    I only have a mite of experience with animation to FBX (meant for Unity), but I haven't had much issues with just ticking the animation box. I've worked with people who tried the same thing and didn't get proper results, and the only difference we found was in which version of FBX exporter we used, as they were on 2009 when I was using 2011. I also mostly only dealt with getting everything baked to individual keyframes, as there were always errors when trying to output with curves and such.
  • bugo
    Offline / Send Message
    bugo polycounter lvl 17
    Just used this fantastic script, thanks Haidalasami, this needed a bump!
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Awesome Bugo! Glad to see people still have a use for this :)
  • dproeder
    Offline / Send Message
    dproeder polycounter lvl 5
    You have just made my day. I've been working on simulations with over 100 separate meshes to import into unity. I always name things in the outliner so this script just saved me 30 mins of mindless exporting. much love.
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Glad to see people still have a use for this :) Hope you're exporting went well.
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Awesome np Dustin. Hope it worked out for you!
  • dproeder
    Offline / Send Message
    dproeder polycounter lvl 5
    I just tried out the script in maya 2015, and it seems to take a LONG time to export now. Has anyone else come across the error yet?
  • rorozilla
    Offline / Send Message
    rorozilla polycounter lvl 6
    Hey haiddasalami! love your scrip! I've been using it to for the past week and didn't have a problem, but for some reason starting yesterday, when ever I use it, it wont export all the objects selected in my scene. only part of my selection will be exported. Strangely though, if I export one by one using your script, I don't have a problem. What am I doing wrong? I am using Maya 2014, just so you know.

    Thanks a bunch for the awesome script!
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    dproeder wrote: »
    I just tried out the script in maya 2015, and it seems to take a LONG time to export now. Has anyone else come across the error yet?

    Hey not sure about this. Will try it on 2015 but are you using LT by any chance?

    EDIT:Tested in 2015. Didnt notice a slow down.
    rorozilla wrote: »
    Hey haiddasalami! love your scrip! I've been using it to for the past week and didn't have a problem, but for some reason starting yesterday, when ever I use it, it wont export all the objects selected in my scene. only part of my selection will be exported. Strangely though, if I export one by one using your script, I don't have a problem. What am I doing wrong? I am using Maya 2014, just so you know.

    Thanks a bunch for the awesome script!

    Thanks! Not sure what it is. Mind hosting the ma/mb file somewhere to test or showing what the outliner looks like.
  • rorozilla
    Offline / Send Message
    rorozilla polycounter lvl 6
    Absolutely! what would be the best way to share my file with you? Could Email work for you? I would rather not share it publicly if possible.

    And on further examination, I notice it seams to fail on a specific items: it will go troughs the list of items in my Outliner in order (First selected to last selected) but the moment it selects a specific object, it will move it (if i ticket center to grid) but not export it. And to correct what I said earlier, even if I select the item alone, it will NOT export it as normal. So maybe its something wrong with my model but I didn't treat it any differently then the others.

    On an other note, changing the name of the problematic item seamed to fix it, but how would that make any sense?
  • rorozilla
    Offline / Send Message
    rorozilla polycounter lvl 6
    Ok, Dropbox's security settings are pretty shitty now wow! But ill be hosting it temporarily There for this issue. Let me know when you have your hands on it so I can remove it.

    So the problematic item is Skeleton_Pelvis

    Its weird that changing the name seams to fix it, its not like Maya would even allow me to have two items named the same.
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Whoops sorry. Stepped away from desk. You can remove it now. Will take a look. Possibly conflicts with shape name.

    EDIT: Yup its name conflict. So inside my code I call Maya Short Name instead of Full Name (was a noob back then XD) so it trys to select Skeleton_Pelvis but there is a skeleton pelvis inside skeleton_small and one in the root of the scene.
  • rorozilla
    Offline / Send Message
    rorozilla polycounter lvl 6
    Ok! Sweet! So is there a way I could modify your scrip to make it work on my items? or would you suggest I simply make sure my items don't share the same name?
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    /*
    Created by Alistair Braz (Haiddasalami)
    Version 1.01
    
    Installation:
    1. Download the .mel file.
    2. Place it in your My Documents/maya/scripts folder.
    3. Re-start Maya and type fbxExporter; in the MEL command line to launch the tool.
    4. Make shelf button or add to marking menu's for profit.
    
    TO DO:
    
    - Implement ASE batch export
    - Implement sets
    - Implement quick pivot changes as second tab.
    - Implement some sort of quick export options like recently used paths/last used options.
    - Write this in python :)
    
    Version Changes
    
    V1.01 - Option to keep original location while centering pivot has been implemented
    V1.0 - Initial release 
    */
    
    global proc fbxExporter() {
        
        if (`window -exists fbxExporterWindow`) 
            { 
                // if Window exists delete, so you cant call multiple windows
                deleteUI fbxExporterWindow;
            }
            
    //Declaring window and naming it 
        window -resizeToFitChildren 1 -t "FBX Batch Exporter" -minimizeButton 1 -maximizeButton 1 -w 250 -h 50 fbxExporterWindow;
        columnLayout -adjustableColumn 1 -rowSpacing 0 MainColumnLayout;
            text -label "Source Directory:" -align "left";
            textField -w 218 -fi "" sourcePath; 
            button -label "Set default output path" -h 20 -ann "Browse for source folder..." -c "fileBrowserDialog -m 4 -fc \"setSource\" -ft \"directory\" -an \"Select Source Folder\""; 
            checkBox -label "Center To Grid" centerPivot; 
            checkBox -label "Keep Original Location" originalLoc;        
            checkBox -label "Preserve Smoothing Groups"  smoothingGroup;
            checkBox -label "Preserve Mesh Input Connections" meshConnections; 
            button -label "Export" -command "fbxExport";
      
        setParent ..;
        //Display the Window
        showWindow fbxExporterWindow;
        string $plugin = "fbxmaya";
    	if ( catch( `loadPlugin -quiet $plugin` ) ) {
    		warning( "Plug-in '" + $plugin + "' was not found. FBX Export features will not be available." );
    		return;
    	}
    }
    
    global proc setSource(string $filename, string $fileType){
        $filename = $filename + "/";    
        textField -e -fi $filename sourcePath;
    }
    
    global proc centerPiv(string $objSelection){
            select -r $objSelection;
            makeIdentity -apply true -t 1 -r 1 -s 1 -n 0;
            $Pos = `xform -q -piv -ws`;
            move -a  (-1 *  $Pos[0]) (-1*$Pos[1] ) (-1*$Pos[2]) ;
            //makeIdentity -apply true -t 1 -r 1 -s 1 -n 0;
    }
    
    global proc fbxExport() {
        string $concatedtext;
        string $array[] = {};
        string $sel[] = `ls -sl -l`;
        string $thisObj;  
        string $path = `textField -q -fi sourcePath`;
        int $smoothingB = `checkBox -q -v smoothingGroup`;
        int $meshConnectionsB = `checkBox -q -v meshConnections`;
        int $originalLocB = `checkBox -q -v originalLoc`;
        string $extension = ".fbx";
        int $sizeSel = size($sel);  
        string $check = `checkBox -q -v centerPivot`;
        if ($sizeSel == 0){
            warning("Nothing is selected");
            confirmDialog -title "Error" -message "Nothing is selected" -button "OK" -defaultButton "OK" -cancelButton "CANCEL";
        }
        else {
        if ($check == true){
            if ($originalLocB == true){
                for ($thisObj in $sel){
                select $thisObj; 
                $OriginalLoc = `xform -q -piv -ws`;
                string $tokTmp[];
                int $count = `tokenize $thisObj "|" $tokTmp`;
                string $result = $tokTmp[$count - 1];           
                $concatedtext = $path + "/" + $result + $extension;      
                centerPiv($thisObj);    
                FBXExportSmoothingGroups -v $smoothingB;
                FBXExportInputConnections -v $meshConnectionsB;
                FBXExport -f $concatedtext -s;
                move -r $OriginalLoc[0] $OriginalLoc[1] $OriginalLoc[2] $thisObj;  
                }  
            }
            else {
                for ($thisObj in $sel){
                select $thisObj;              
                string $tokTmp[];
                int $count = `tokenize $thisObj "|" $tokTmp`;
                string $result = $tokTmp[$count - 1];           
                $concatedtext = $path + "/" + $result + $extension;           
                centerPiv($thisObj);    
                FBXExportSmoothingGroups -v $smoothingB;
                FBXExportInputConnections -v $meshConnectionsB;
                FBXExport -f $concatedtext -s;  
                }  
            }
    
        }
        else {
            for ($thisObj in $sel){
                select $thisObj;                
                string $tokTmp[];
                int $count = `tokenize $thisObj "|" $tokTmp`;
                string $result = $tokTmp[$count - 1];           
                $concatedtext = $path + "/" + $result + $extension;             
                FBXExportSmoothingGroups -v $smoothingB;
                FBXExportInputConnections -v $meshConnectionsB;
                FBXExport -f $concatedtext -s;  
            }
        }
      }   
             
    }
    

    Just open up the script and copy and paste that in. Should work exactly the same. Seems when two conflicts like that happen. Maya forces the second mesh to take the long name of the mesh. Ill update the dropbox mel file when I get back home. Hope that helps :) Weird reading code I wrote like 3 years ago haha
  • rorozilla
    Offline / Send Message
    rorozilla polycounter lvl 6
    Thank you so much haiddasalami!!
    You really saved my buns!! It works perfect now!

  • < ASH >
    Offline / Send Message
    < ASH > polycounter lvl 13
    Hey Haiddasalami, 

    I just wanted to say "many thanks" for developing and sharing this utility. :)
    Today I test it out with Maya 2016 and it still works like a charm: it's a great time saver tool. ;)
  • SeanToomey
    Great script.....  Would it be possible to control the scale of the export (cm, meters etc) like you can in the fbx options?  Also, maybe an option to triangulate?
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Hey, Sure I can take a look today during lunch. Glad to see people still have a use for this :)
  • McGergs
    Offline / Send Message
    McGergs polycounter lvl 9
    This script is outstanding! I am having to use it for Knald since it does not using baking groups or support multiple meshes in an FBX file. This has saved me a lot of time. Thank you!
  • HomeGrownHeroz
    Offline / Send Message
    HomeGrownHeroz polycounter lvl 6
    Hi, I've just started using this script and it's such a time saver so thanks so much for sharing it. I wondered if it's possible to have a setting that remembers the Source Directory when the script re-opens. How could this be done? Thanks!
  • Zefaistos
    Offline / Send Message
    Zefaistos polycounter lvl 2
    I found this script today and I don't know how I lived so far without this. This is freaking awesome, thanks for sharing with us.
  • TheNandavar
    Hi, I am trying to run this script on MAYA 2017. After copying the .mel file to the scripts folder and adding the script to the Shelf, the UI window doesn't launch nor do I get any warnings/ errors. Is there anybody who has tested this script with Maya 2017 and can offer some advice on how to get this to work. It will be the best thing to have for my Project!!

    Thanks in Advance :)
  • Radeon
    Offline / Send Message
    Radeon polycounter lvl 7
    First off all - thanks for very usefull script. It helps me a lot. Can you add the ability to export locators, that are parented to the object as well? Currently its exports them as different objects , with different names.
  • BitGem
    Offline / Send Message
    BitGem polycounter lvl 9
    @haiddasalami ... mate your script has been my faithful companion since 2011 and I have been exporting TONS of assets with it. Can't tell you in words how helpful it's been. ...Now I've moved to Maya LT 2017 on a mac ... AND IT STILL WORKS!!! :D 
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Thanks for the kind words @BitGem. I unfortunately dont get any messages if people reply but tagging them seems to work. @Radeon if you still have a use for it, Ill put together something during my lunch and message you. 
  • Dennispls
    Offline / Send Message
    Dennispls polycounter lvl 16
    @haiddasalami Gonna give this a go too! Thanks for supplying us with this script man. Apreciate it
  • MaddHattPatt
    @haiddasalami I came across this script a few years back to speed up some of my work. A few computers and maya versions later and this script is still coming in handy. Thank you very much!
  • [HP]
    Offline / Send Message
    [HP] polycounter lvl 13
    Hey @haiddasalami, seems like the file has been taken down from dropbox. Do you have a mirror somewhere? 

    Thanks,
    HP
  • alekseypindrus
    Offline / Send Message
    alekseypindrus polycounter lvl 10
    @[HP] Just copy code from message and save it as .mel file. Also check pbUDK.
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Sorry Helder (@[HP]). Was trying out Dropbox Business guess it screwed up my links? Anywho moved it to google drive in case that happens again. 

    Thanks for the kind words @MaddHattPatt and @Dennispls

  • Christian Cunningham
    Offline / Send Message
    Christian Cunningham polycounter lvl 10
    I cant seem to get this to work, I copied the script above, saved, pasted into maya, saved it as mel, put it in my scripts folder, made shelf icon, and when I restart and click the button all it does is echo the code in my script editor but nothing happens. 
  • sprunghunt
    Offline / Send Message
    sprunghunt polycounter
    I cant seem to get this to work, I copied the script above, saved, pasted into maya, saved it as mel, put it in my scripts folder, made shelf icon, and when I restart and click the button all it does is echo the code in my script editor but nothing happens. 
    does your mel button call fbxExporter(); ?
  • McGergs
    Offline / Send Message
    McGergs polycounter lvl 9
    @haiddasalami I just wanted to let you know I still use this in Maya 2018 and wanted to reach out with a thank you!
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    @McGergs Sorry been on vacation in the UK. No worries! Glad it still works and people have a use for it :)
  • Minos
    Offline / Send Message
    Minos polycounter lvl 16
    Hey man! I just wanted to say that I've been improving my workflow on Unity and this was perfect! I've been searching for an script that exports locators (so I can have multiple objects exported as one) and this one is simple and perfect. Thank you again!
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    No worries Thiago! Learned a lot from your breakdowns back in the day so glad I can help you out now haha

  • artbywaqas
    Offline / Send Message
    artbywaqas polycounter lvl 11
    I'm not sure what's going wrong but I'm finding that sometimes during export using this script the model moves to 0,0,0 but when I view the resulting fbx file in Unreal I'm finding the model is far away from pivot I manually  set up in Maya.  

    I've been using this script for years without problem. I'm wondering if it's perhaps a glitch with Maya 2016 or perhaps I am doing something different with some of my models without knowing that's causing this.








1
Sign In or Register to comment.