from pyfbsdk import FBSystem, FBApplication, FBFilePopup, FBFilePopupStyle, FBFbxOptions
def getFileName(f):
import os
d, filename = os.path.split(f)
if filename:
return os.path.splitext(filename)[0]
else:
return "unknown"
lSystem = FBSystem()
lApplication = FBApplication()
lFileName = lApplication.FBXFileName
if lFileName == "":
FileDlg = FBFilePopup()
FileDlg.Style = FBFilePopupStyle.kFBFilePopupSave
FileDlg.Caption = "The current filename is not valid."
FileDlg.FileName = "Untitled.fbx"
FileDlg.Filter = "*"
if FileDlg.Execute():
lFileName = FileDlg.FileName
if lFileName.upper().endswith( '.FBX' ):
lOptions = FBFbxOptions(False)
lOriginalTake = lSystem.CurrentTake
for lTake in lSystem.Scene.Takes:
lSystem.CurrentTake = lTake
lTakeFileName = "%s-%s.fbx" % ( getFileName(lFileName), lTake.Name )
print "Saving Take '%s' to file '%s'" % ( lTake.Name, lTakeFileName )
lOptions.UseASCIIFormat = True
for index in range(lOptions.GetTakeCount()):
if lOptions.GetTakeName(index) == lTake.Name:
lOptions.SetTakeSelect(index, True)
else:
lOptions.SetTakeSelect(index, False)
lApplication.FileSave( lTakeFileName, lOptions )
lSystem.CurrentTake = lOriginalTake
del( lOriginalTake, lOptions )
else:
print 'File name does not end with ".fbx". Unable to proceed!'
del( lSystem, lApplication, lFileName )
del( FBSystem, FBApplication )