from Modes import SelectionMode
from ScriptRunner import ScriptRunner
import os.path, glob, time
class ConvertApfToFbx( ScriptRunner ):
def __init__( self, scriptName, args ):
ScriptRunner.__init__( self, scriptName, args )
self.myDir = os.path.dirname(scriptName)
self.myLog = None
self.myFileNum = 0
def Main( self ):
self.myLog = open( os.path.join(self.myDir,"logfile.txt"), "w" )
for apfName in glob.glob( os.path.join(self.myDir, "*.apf" ) ):
fbxName = self.fbxToConvert( apfName )
if fbxName:
self.fbxCreate( apfName, fbxName )
self.myLog.write("Found %s .APF file(s) in %s." % (self.myFileNum, self.myDir))
print "Found %s .APF file(s) in %s." % (self.myFileNum, self.myDir)
self.myLog.close()
def write( self, msg ):
if self.myLog is not None:
self.myLog.write( "%s\n" % (msg) )
self.myLog.flush()
print msg
def fbxToConvert( self, apfName ):
(fbxName, extension) = os.path.splitext(apfName)
fbxName = fbxName + ".fbx"
self.myFileNum+=1
return fbxName
def fbxCreate( self, apfName, fbxName ):
timeStart = time.time()
self.write( "Processing %s" % (apfName) )
self.write( " FBX %s" % (fbxName) )
self.sendMessageSync( 'APPLICATION_NEW_SCENE', () )
self.write( " Importing %s" % (apfName) )
self.sendMessage_( 'MODEL_IMPORT', ( '', apfName, True ) )
self.write( " Import completed for %s" % (apfName) )
self.sendMessage_( 'SELECT', ( (), SelectionMode.kReplace ) )
self.sendMessage_( 'REFRESH', () )
self.sendMessage_( 'FIT_TO_VIEW', ( False, ) )
self.write( " Exporting %s" % (fbxName) )
exportHow = 0
exportHow += 512
exportHow += 2048
self.sendMessageSync( 'APPLICATION_EXPORT_SCENE', ( fbxName, (),
exportHow, ) )
self.write( " Closing %s" % (fbxName) )
self.sendMessageSync( 'APPLICATION_CLOSE_SCENE', () )
timeEnd = time.time()
self.write( "Done in %.1f seconds" % (timeEnd - timeStart) )
def instantiate( scriptName, args ):
return ConvertApfToFbx( scriptName, args )