Home Technical Talk

Batch Exporter Problem

I've written a batch exporter using bits and pieces of code I've cobbled together. src_files is an array that stores a list of max files to export. There a few variables which store whether or not to save a max file, which units to set and save locations of the max files and export flt files.

The exporter works really well, however I tried running it on a folder of over 500 max files, but it would crash with certain files. I will get an unknown system exeption error. Then in the listener I get "Error occurred in f loop; .." and it stops on the LoadMaxFile line.

Is there a way to script it so that instead of crashing on LoadMaxfile it will return to the loop and log the files it can't load?

Here's the main part of the exporting loop:
if src_files.count != 0 then
        (
            max file new
            units.DisplayType=#us
            units.SystemType=reScale
        
            for f = 1 to src_files.count do 
            (
                --LoadMaxFile "C:\\blankfile.max" quiet:true useFileUnits:true
                --units.DisplayType=#us
                --units.SystemType=reScale
                
                src_file = src_files[f]
                dest_name = (GetFilenameFile src_file)
                dest_file = VexportFLT + "\\" +dest_name + ".flt"
                
                missingDLLs = undefined
                missingExt = undefined
                LoadMaxFile src_file quiet:true useFileUnits:false missingExtFilesAction:#logmsg missingExtFilesList:&missingExt  missingDLLsList:&missingDLLs missingDLLsAction:#logmsg
                print ("Exporting " + src_file + " to " + dest_file)
                PolyTrans.Export dest_file "" ".flt" "" "" 0 0
                if VexportMaxState == "true" then
                (
                    --Save max file
                    saveMaxFile(VexportMax + "\\" + maxFileName)--save new max file
                    print ("Saved max file")
                )
            )
            messagebox ("Export complete. " + (src_files.count as string) + " files exported.")
        )
        else
        (
            messagebox ("No Max files found in batch export location")
        )
I think I've pinned down the files that it's having difficulty loading, but the files actually load OK when opening them in max as normal. If I collapse the stacks, reset the Xforms and then save, the exporter will work as usual. If I could automate this into the exporter that would be great but since they won't load through the loadMaxFile function I've no idea how to do that! :shifty:

I forgot to say I don't think it's a memory error since when running the script on the broken files alone, the script will still crash. I did try increasing the memory available to max script but that didn't help.

EDIT: I also tried creating a blank max file and loading this first in the loop so it would always go file1 > blank > file2 > blank etc rather than go file1 > file2 > file3. This made no difference.

Replies

  • eddybrown
    Options
    Offline / Send Message
    Ok I haven't got anywhere with the script with the exception that I've found that objects that are not editable poly are causing the script to break. In particular these are objects that start life as boxes, or lines with edit poly and uvunwraps in the stack.

    I tried using PENs great batch exporting script with the following script to try and clean up the files before export:
    for g in geometry do
        (
            currentname = maxFileName
            tempname = ("OLD" + maxfileName)
            if (g.baseObject as string != "Editable Poly") do  
                (
                    saveMaxFile(maxFilePath + tempname)
                    print "Stupid Shapes!"
                    convertTo g PolyMeshObject
                    resetXForm g
                    convertTo g PolyMeshObject
                    saveMaxFile(maxFilePath + currentname)
                )
        )
    
    What happens is the script will save say 2 max files then crash with unknown system error at the convertTo g PolyMeshObject line. Am I doing something wrong?
  • eddybrown
    Options
    Offline / Send Message
    I've since found out that using the script above with PENs script works perfectly in 64bit. So now I have to clean the files before exporting in 64 bit, then export in 32 bit since the exporter will only run in 32bit. Not ideal but it's a workaround.

    I also tidied up the script so that it didn't save during the loop as my intention was to save a before and after file.
    -- Declare Variables
    currentname = maxFileName
    tempname = ("OLD_" + maxfileName)
                        
    -- Check if objects in scene need cleaning, add 1 if they do
    for g in geometry do
          (
              if (g.baseObject as string != "Editable Poly") do
                   (
                      objectsThatNeedCleaning = objectsThatNeedCleaning + 1
                    )
              )
                        
    -- If objects need cleaning then clean.
    if objectsThatNeedCleaning > 0 then
          (
              --save max file with prefix OLD_
              saveMaxFile(maxFilePath + tempname)
    
              print ("Bloody Shapes! Cleaning " + maxFileName)
    
              -- append cleanValue so it knows how many files have been processed
              cleanValue = cleanValue + 1
    
              -- actually clean geometry
              for g in geometry do
                   (
                       convertTo g PolyMeshObject
                       resetXForm g
                       convertTo g PolyMeshObject
                       gc()
                   )
    
              -- reset objects that need cleaning counter    
              objectsThatNeedCleaning = 0   
     
              -- save max file
              saveMaxFile(maxFilePath + currentname)
         )
    
      else
         (
               print (maxFileName + " is clean")
          )
    
  • monster
    Options
    Offline / Send Message
    monster polycounter
    use Try() and catch() to skip over crashing sequences. Using try and catch can slow down processor intensive loops, but for a batch exporter it should be fine.

    Ffor example say MyMaxFiles is an Array of max file names. The following code will try to export all files. If there is an exception, the loop will skip the error and print the file name to the listener.
    for MyMaxFile in MyMaxFiles do
    (
        try
        (
            if loadmaxfile MyMaxFile quiet:true do
            (
                --EXPORT STUFF
            )
        )
        catch
        (
            format "FILE FALED TO EXPORT: %" MyMaxFile
        )
    )
    
    
  • renderhjs
    Options
    Offline / Send Message
    renderhjs sublime tool
    try and catch is on thing, the other thing I experienced to be valuable is to use a delay call which holds the script to hold for a few ms or seconds before it continues. Especially some of the export plugins (FBX in particular) may take longer and do not sync always with maxscript. So in those cases I often add a delay to prevent a heap.
Sign In or Register to comment.