Tasks/JpegRender.py

Tasks/JpegRender.py
1 # Copyright 2009 Autodesk, Inc. All rights reserved.
2 # Use of this software is subject to the terms of the Autodesk license agreement
3 # provided at the time of installation or download, or which otherwise accompanies
4 # this software in either electronic or hard copy form.
5 #
6 # Topic: FBVideoGrabber, FBVideoGrabber.GetOptions, FBApplication.FileRender
7 #
8 
9 from pyfbsdk import *
10 
11 import tempfile
12 import os
13 import os.path
14 
15 # Create an application object.
16 lApp = FBApplication()
17 
18 # We need the full path of the output file.
19 if lApp.FBXFileName!="":
20  lDstFileName = lApp.FBXFileName.replace( '.fbx', '.jpg' )
21 else:
22  lDstFileName = os.path.join( tempfile.gettempdir(), 'Default.jpg' )# WARNING: If the current scene has yet to be named (i.e. after a File->New), this script will set the render path to TEMPDIR/Default.jpg
23 
24 # Get the default rendering options, which are saved in the FBX file.
25 lOptions = FBVideoGrabber().GetOptions()
26 
27 # Set the name of the rendered file.
28 # The rendering will be done in the same folder as the original FBX file.
29 lOptions.OutputFileName = lDstFileName
30 
31 # Setup the compression level.
32 # The value should be between '1' and '100', and indicates the size of
33 # the compressed rendered file vs the size of an uncompressed rendered
34 # file. In other words, '100' means 'no compression'.
35 # As the value tends towards 1, the quality of the rendered frame will
36 # decrease.
37 lOptions.StillImageCompression = 40
38 
39 # Enable audio rendering. The file name will be the same as the FBX file,
40 # but will have a .wav extention.
41 lOptions.RenderAudio = True
42 
43 # Do the render. This will always be done in uncompressed mode.
44 if not lApp.FileRender( lOptions ):
45  print 'An error was found rendering : ' + FBVideoGrabber().GetLastErrorMsg()