Search Unity

maya looping an export on each frame

Discussion in 'Asset Importing & Exporting' started by jin76, Jan 11, 2014.

  1. jin76

    jin76

    Joined:
    Mar 4, 2010
    Posts:
    364
    Hello, I have the task of exporting every frame of several animations as separate obj files. I am trying to automate this process via MEL scripting. Although I am just a beginner in Mel scripting I have tried my best to write the script. I have written most of the script however i am having a hard time with changing the name of the file after each export so that it doesn't replace the previous. Here is what I have so far:
    Code (csharp):
    1.  
    2. for ( $i =1 ; $i <=50; $i++)
    3.  {
    4.    
    5.  currentTime $i ;
    6.   file -force -options "groups=1;ptgroups=1;materials=1;smoothing=1;normal  s=1" -type "OBJexport" -pr -ea "C:/Users/Com/Desktop/Models/Model_01_rig/Keyboard/test_1/model.obj";
    7.  
    8.  }
    As you can see its a simple for loop however what ends up happening is that each export replaces the file created before it due to them having the same file name. I need a way to change the export file name after each export so it shows up as 50 differently named files.

    I hope someone can help me,
    Thanks.
     
    Last edited: Jan 11, 2014
  2. SomeDude

    SomeDude

    Joined:
    Feb 16, 2012
    Posts:
    95
    See if this works.

    Code (csharp):
    1.  
    2. for ( $i =1 ; $i <=50; $i++)
    3. {  
    4. currentTime $i ;
    5.  
    6. file -force -options "groups=1;ptgroups=1;materials=1;smoothing=1;normal  s=1" -type "OBJexport" -pr -ea ("C:/Users/Com/Desktop/Models/Model_01_rig/Keyboard/test_1/model" + $i +".obj");
    7.  }
    8.  

    Edit: This should work but each time you want to save a new batch of 50 you'll have to change the directory or filename in the code above. So, it can be made more useful if it pops up a browse to file directory which also allows typing or pasting a directory or changing just the filename each time it's run to save out a new batch instead of having to change the directory in the code. Also it could be made to test if the filename already exists in the directory and then pop up the directory change window again if it does so you can change the name or directory.

    If you want I can write that for you but give me a little while as I'm still waking up and need to go cook some breakfast. Just let me know.
     
    Last edited: Jan 11, 2014
  3. jin76

    jin76

    Joined:
    Mar 4, 2010
    Posts:
    364
    It works !, I was trying to concatenate just as you have done, however i was forgetting the brackets (-____-)" ,
    Anyways, thanks alot,

    Edit: Thats np man , I can figure that out, i have sort of an idea on how to do that, I'l ask for help if i need.
     
    Last edited: Jan 11, 2014
  4. SomeDude

    SomeDude

    Joined:
    Feb 16, 2012
    Posts:
    95
    Oh I see. Sounds like you know how to code well enough to figure it out yourself then. :) I wasn't sure how new you were.

    Just search for "file" in the maya command reference here:

    http://download.autodesk.com/global/docs/maya2014/en_us/Commands/index.html

    Been a few years since I coded my custom exporter so I don't remember exactly but I think you'll find everything you need in the search results for "file".

    But yeah if you run into problems don't hesitate to ask. :)