Search code examples
pythonfbx

Convert *.obj to *.fbx with Python FBX SDK


I try to find some documentation for Autodesk Python FBX SDK, but it seems that it is available only for C++ (http://help.autodesk.com/view/FBX/2015/ENU/?guid=__files_GUID_50489A8A_457C_4B54_80E1_5572A16F7F17_htm).

Does somebody know how convert *.obj to *.fbx with using Python FBX SDK?

Thanks.


Solution

  • Python FBX SDK lacks good documentation. Here is how you might get it to work.

    import fbx
    
    # Create an SDK manager                                                                                           
    manager = fbx.FbxManager.Create()
    
    # Create a scene
    scene = fbx.FbxScene.Create(manager, "")
    
    # Create an importer object                                                                                                  
    importer = fbx.FbxImporter.Create(manager, "")
    
    # Path to the .obj file
    milfalcon = "samples/millenium-falcon/millenium-falcon.obj"
    
    # Specify the path and name of the file to be imported                                                                            
    importstat = importer.Initialize(milfalcon, -1)
    
    importstat = importer.Import(scene)
    
    # Create an exporter object                                                                                                  
    exporter = fbx.FbxExporter.Create(manager, "")
    
    save_path = "samples/millenium-falcon/millenium-falcon.fbx"
    
    # Specify the path and name of the file to be imported                                                                            
    exportstat = exporter.Initialize(save_path, -1)
    
    exportstat = exporter.Export(scene)
    

    Optionally, you can set export (and import) options with i.e.

    ios = fbx.FbxIOSettings.Create(manager, fbx.IOSROOT)
    manager.SetIOSettings(ios)
    
    manager.GetIOSettings().SetBoolProp(fbx.EXP_FBX_SHAPE, False)
    manager.GetIOSettings().SetBoolProp(fbx.EXP_FBX_GOBO, False)
    
    exportstat = exporter.Initialize(save_path, -1, manager.GetIOSettings())