Tyler Thornock
Technical Animator
Home Tutorials Tools Rigs About/Resume
FBX – Query Original Scene File

This will show you how to query a property found within an FBX, namely, the one that stores the path of the Maya scene that was open during the export. I have only used this for files from Maya, so am not sure if it will work for other programs, and in certain cases (like having an unsaved scene), this will not be valid/missing.

To get started, you will need to install the Python FBX SDK, as it is not installed by default. I am not aware of a way to query these properties with the commands provided by the FBX plugin included with Maya.

To get a better idea of what properties are stored, just export an fbx in ascii instead of binary, which is found under the FBX Export options under Advanced Options – FBX File Format.

Then you can just open the file in a text editor and check out the header, here is an example of what is in the SceneInfo section.

To begin coding, you will need to create an FbxManager, FbxImporter and then initialize the importer to the desired path. You can also check the status of the initialization.

import fbx

path = r"D:\exported_file.fbx"

manager = fbx.FbxManager.Create()
importer = fbx.FbxImporter.Create(manager, 'tempImporter')
status = importer.Initialize(path)

if status is False:
    # this may not work depending on your version
    raise Exception('Failed, {}'.format(importer.GetLastErrorString()))
    # so afaik, you will have to use a generic message, could be worth pinging autodesk about this
    raise Exception('FBXImporter initialization failed.')
    

Now you will need to create a FbxScene and Import the data (if you are in Maya, this does not create objects in your current scene). Now you can access the several types of header-ish type of information via GetSceneInfo to get an instance of FbxDocumentInfo, which can includes things like a thumbnail, application name, application native file, etc.

scene = fbx.FbxScene.Create(manager, 'tempScene')
importer.Import(scene)
info = importer.GetSceneInfo()

Finally, use the FbxDocumentInfo to lookup the desired property. At this point, C++ would allow you to do a .Get on the property, buuuut for Python you need to cast it to the correct FbxProperty type, in this case I already know it is a string.

After casting to the correct type, you can just do a .Get() to get the value… now you know the original Maya file!

prop = info.FindPropertyHierarchical('Original|ApplicationNativeFile')
if prop.IsValid():
    casted_prop = fbx.FbxPropertyString(prop)
    prop_value = casted_prop.Get()

# if you do not do this step the file will not be closed (use a try/finally or something to make sure it is always done)
importer.Destroy()
If you don’t already know the type of a property, you can look it up via prop.GetPropertyDataType().GetType(). Sadly, you would need to detect and cast it properly… probably time for an annoying helper function… and even then there are a lot of different property types.

def get_prop_value(prop):
    # annoying auto-cast function, eww
    casted_prop = None
    prop_type = prop.GetPropertyDataType().GetType()
    if prop_type == fbx.eFbxBool:
        casted_prop = fbx.FbxPropertyBool1(prop)
    elif prop_type == fbx.eFbxDouble:
        casted_prop = fbx.FbxPropertyDouble1(prop)
        
    return casted_prop