Building FBX Python Bindings for Maya 2023

Instructions on how to build fbx.pyd and fbxsip.pyd on Windows


็›ฎๆฌก


The FBX-related files distributed by Autodesk include Python Bindings that allow you to read and write FBX files via Python. However, these pre-built bindings are available only for Python 3.7. They can't be used with other Python versions, including Python 3.9 used in Maya 2023. Also, there are no official build instructions, and the provided files are full of pitfalls. This article will focus only on the Windows environment, although similar issues likely apply to other platforms.

Build Environment

First, prepare the necessary build environment and compiler. Download the BuildTools for Visual Studio installer from Microsoft and install the version required for Python 3.9, which is 2019 in this case. You will also need a Python 3.9 environment. Alternatively, you can use mayapy, but this article will not cover setting it up due to its complexity.

Collecting Necessary Files

Next, gather the files required for building. Download the following from Autodesk's website:

  • FBX SDK 2020.3.2 VS2019
  • FBX SDK 2020.3.2 Python
  • FBX SDK 2020.3.2 Python Bindings

Also download

Old articles may direct you to download SIP from Riverbank, but it is difficult to find the required version, so downloading from Sourceforge is recommended. Note that the build will fail with the last version of SIP v4, v5, or v6. Place these files in a directory with no spaces in the file path (e.g., d:\fbx) because the build scripts are not designed to handle spaces.

Editing the Build Script

Edit the provided file PythonBindings/2020.3.2/PythonBindings.py. The compiler version is hardcoded, so make the necessary changes.

- vsCompiler = "vs2015"
+ vsCompiler = "vs2019"

Also, update the path to vcvars.bat, as it is not compatible with the build tools by default.

def vcvars(platform_tag):
+   # ใกใ‚ƒใ‚“ใจใ™ใ‚‹ใฎ้ขๅ€’ใ ใฃใŸ
+   return "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Auxiliary/Build/vcvars64.bat"
+     
    prefix = vcCompiler.replace('vc', 'VS')
    vc_common_tool_dir = os.path.expandvars('$'+prefix+'COMNTOOLS')
    if platform_tag == 'FBX_X64':
        result = os.path.normpath(os.path.join(vc_common_tool_dir, '../../VC/bin/amd64/vcvars64.bat'))
    else:
        result = os.path.normpath(os.path.join(vc_common_tool_dir, '../../VC/bin/vcvars32.bat'))
    return result

Build

After the preparations, run the build script.

cd /d %~dp0

SET FBX_VERSION=2020.3.2

SET FBXSDK_ROOT=D:\fbx\FBXSDK\%FBX_VERSION%
SET FBXSDK_LIBS_64_FOLDER=D:\fbx\FBXSDK\%FBX_VERSION\lib\vs2019\x64\release
SET SIP_ROOT=D:\fbx\sip-4.19.13

cd D:\fbx\PythonBindings\%FBX_VERSION%
python PythonBindings.py Python3_x64 buildsip

Execute these commands in the Command Prompt. Successful execution will generate the necessary files under D:\fbx\PythonBindings\2020.3.2\build\Distrib\site-packages.

cheers!