# Copyright 2009 Autodesk, Inc. All rights reserved. # Use of this software is subject to the terms of the Autodesk license agreement # provided at the time of installation or download, or which otherwise accompanies # this software in either electronic or hard copy form. # # Topic: FBRenderer, FBVideoGrabber, FBVideoRenderDepth, FBVideoRenderDepth, FBVideoCodecManager, FBVideoCodecMode # from pyfbsdk import FBMessageBox, FBApplication, FBVideoGrabber, FBVideoRenderDepth, FBVideoRenderDepth, FBVideoCodecManager, FBVideoCodecMode import sys, os from os import environ, listdir # We use a try/except block, because the call to 'listdir' can fail. try: # We take for granted that the folder containing the FBX files is # indicated with the environment variable 'RENDER_SRC_FOLDER'. lRenderSrcFolder = None if environ.has_key( 'RENDER_SRC_FOLDER' ): lRenderSrcFolder = environ['RENDER_SRC_FOLDER'] else: # We have failed to find the folder containing the FBX files... # The environment variable is probably not defined. FBMessageBox( "ERROR", "The environment variable 'RENDER_SRC_FOLDER' is not defined... Cannot proceed.", "OK", None, None ) FBApplication().FileExit() # And the place where to store the rendered scene is indicated by # the environment variable 'RENDER_DST_FOLDER'. lRenderDstFolder = None if environ.has_key( 'RENDER_DST_FOLDER' ): lRenderDstFolder = environ['RENDER_DST_FOLDER'] else: # We have failed to find the folder where to save the renders... # The environment variable is probably not defined. FBMessageBox( "ERROR", "The environment variable 'RENDER_DST_FOLDER' is not defined... Cannot proceed", "OK", None, None ) FBApplication().FileExit() # The file format of the render is indicated by 'RENDER_FILE_FORMAT'. lRenderFileFormat = None if environ.has_key( 'RENDER_FILE_FORMAT' ): lRenderFileFormat = environ['RENDER_FILE_FORMAT'] else: # We have failed to find the folder where to save the renders... # The environment variable is probably not defined. FBMessageBox( "ERROR", "The environment variable 'RENDER_FILE_FORMAT' is not defined... Cannot proceed", "OK", None, None ) FBApplication().FileExit() # If the variable is defined, let's process the files if lRenderSrcFolder and lRenderDstFolder and lRenderFileFormat: # Make sure that the destination folder exists... # Ideally it should be created automatically. listdir( lRenderDstFolder ) # Obtain the list of files in the folder, and sort them alphabetically. lFileList = listdir( lRenderSrcFolder ) # We sort the list lFileList.sort() # Iterate in the list for lFileName in lFileList: # Ensure that we handle only FBX files. if lFileName.endswith('.fbx'): # Create an application object. lApp = FBApplication() # We need the full path of the FBX file to load it. lSrcFileName = os.path.join(lRenderSrcFolder, lFileName) # We also need the full path of the output file. lDstFileName = os.path.join(lRenderDstFolder, lFileName.replace( 'fbx', lRenderFileFormat )) # Open the file in the application. lApp.FileOpen( lSrcFileName ) # Get the default rendering options, which are saved in the FBX file. lOptions = FBVideoGrabber().GetOptions() # Set VideoCodec Option: VideoManager = FBVideoCodecManager() VideoManager.VideoCodecMode = FBVideoCodecMode.FBVideoCodecUncompressed # Set the name of the rendered file. lOptions.OutputFileName = lDstFileName # Only windows supports mov. if lRenderFileFormat == '.mov' and os.name != 'nt': lOptions.BitsPerPixel = FBVideoRenderDepth.FBVideoRender32Bits # Do the render. This will always be done in uncompressed mode. lApp.FileRender( lOptions ) # Clear the scene. lApp.FileNew() except Exception, e: # Unkown error encountered... Maybe from the 'listdir' call failing... FBMessageBox( "ERROR", "Unknown error encountered. Aborting! " + str(e), "OK", None, None ) # Now that we are done, we just exit the application. FBApplication().FileExit()