Saving to a File
 
 
 

Saving to a File

The FBApplication.FileSave() function allows you to save the current scene to a file. This function is equivalent to File > Save As... in the application menu. To avoid any ambiguity, it is recommended to use an absolute file path when saving or loading data.

from pyfbsdk import *

app = FBApplication()

# Use an absolute path to save the file. 
#
# Note: The 'r' before the path indicates that the string 
#       should be used literally, including all escape characters such as '\'.
#
app.FileSave(r'C:\Autodesk\filename.fbx')

In the code sample below, we save the scene to a user-specified location via a popup window. We use the os python module to obtain the current user' s directory (os.path.expanduser('~'), where the '~' stands for the home directory). We then set the default value of FBFilePopup.Path to the current user's My Documents\MB folder.

from pyfbsdk import *
import os

app = FBApplication()

# Save the file using a dialog box.
saveDialog = FBFilePopup()
saveDialog.Style = FBFilePopupStyle.kFBFilePopupSave
saveDialog.Filter = '*'

saveDialog.Caption = 'My Save Dialog Box'
# Set the path to the current user's My Documents\MB folder.
saveDialog.Path = os.path.expanduser('~') + '\Documents\MB'
saveDialog.FileName = 'DancingMan.fbx'

if saveDialog.Execute():
    app.FileSave(saveDialog.FullFilename)

FBX File Embedded Media

If you are using the FBX file format to save your scene data, media such as textures and materials can be embedded within the file. This requires that the FBFbxOptions.EmbedMedia property be set to True (this property is set to True by default). Only the binary FBX file format supports embedded media; the ASCII file format does not support embedded media, but is more human-readable. For more information, see File Options.