Hmmm any good resources? or Builds/Functionality for Batch Scripts? MAYA

Weird question here but I was wondering if there was any good resources or methods to batch run a script over multiple files. A great example of this would be something like Mel Batch
http://www.creativecrash.com/maya/script/mel-batch . I mean something which allows you to run though multiple files while running the script on each one seems pretty sweet. In addition I know that this is all based in Mel however if anyone knows any good alternative methods to allow python or have python setups that would be even better! Thanks for the look and have a good one!

Would something like this work for you:
This example opens every FBX in the file_list, allows you to do stuff to it, and finally saves the result to .mb files.


import pymel.core as pm
import os

root_dir = 'E:/my_project/my_files/'
file_list = [] #list of fbx files
file_list.sort()

for f in file_list:
    pm.openFile('%s%s' % (root_dir, f), force=True, prompt=False)
    try:
        # close the fbx import report prompt/window (it will always open, no matter what flags are set.)
        pm.deleteUI('FbxWarningWindow', window=True)
    except:
        # No window popped up, huzah!, Autodesk must have fixed it.
    
    # Do stuff to content of scene here

    # save the scene to disk as an .mb file.
    pm.saveAs('%s%s.mb' % (root_dir, os.path.splitext(f)[0].lower()), type='mayaBinary')

we have a simple UI with a text field for typing in python command, and a list for adding/removing files.

then we call mayapy.exe and call maya.standalone.initialize().

iterate through the file list and call exec on the contents of the text field and save the file.

Yeah, this is pretty simple in python land.


import logging
import sys

def batch_apply (function, *files, logfile = 'batchlog.txt'):
    logging.basicConfig(filename=logfile,level=logging.DEBUG)
    for eachfile in files:
         try:
            logging.info("started " + eachfile)
            cmds.file(eachfile, open=True, f=True)
            function()
         except:
            logging.exception("error in file " + eachfile)

where ‘function’ is some other function which you want to run in every file. Obviously its more work if you want to put UI on it and so forth but this is all there is to it.