Loading a File

This topic explains how you can load a file from the disk and buffer memory.

Loading from the Disk

The following code sample shows how to load a file from the disk using the FBApplication.FileOpen() function.

from pyfbsdk import *

app = FBApplication()

filename = r"C:\Program Files\Autodesk\MotionBuilder <year>\OpenRealitySDK\scenes\PlasticMan.fbx"

# Open the sample file "PlasticMan.fbx", and prompt with a 
# UI dialog as indicated by the second True argument.
app.FileOpen(filename, True)
Note: It is a best practice to specify an absolute path as an argument to FBApplication.FileOpen(). If you specify a relative path, it corresponds to the current working directory of MotionBuilder. You can change the current working directory in various ways. For example, by manually opening a file or invoking FBPopup.Execute() to specify a location for saving or loading a file.

Loading from the Buffer Memory

To load data from the buffer memory, you must pass the raw address of the buffer memory to FBApplication.FileOpen() instead of a file name. The following code shows how to load data from the buffer memory using FBApplication.FileOpen().

from ctypes import *
fbxfile = r"C:\Program Files\Autodesk\MotionBuilder <year>\OpenRealitySDK\scenes\PlasticMan.fbx"
f = open(fbxfile, 'rb')
buff = create_string_buffer(f.read())
f.close()

FBApplication().FileOpen(addressof(buff), sizeof(buff)) # You can open this file from the memory as many times as you want.

Replacing, Merging, Appending, and Importing

You can use functions in the FBApplication class to control the data loaded from a file. The following table describes these functions.

FunctionDescription
FBApplication.FileOpen()

Opens a file, and replaces the current scene with the loaded data.

This is equivalent to File Open in the application menu.

FBApplication.FileMerge()

Opens a file, and merges the current scene with the loaded data.

This is equivalent to File Merge in the application menu.

FBApplication.FileAppend()

Opens a file, and appends the loaded data to the current scene.

This is equivalent to File Merge in the application menu, with all options set to append.

FBApplication.FileImport()

Opens a file, and imports the animation data contained in the file. If the second parameter of this function is True, the animation data for the models matching the name in a scene is replaced by the imported data.

This is equivalent to File Motion File Import in the application menu.