FBX Python SDK をビルドしてコード補完を実現するまで

に公開

1. Python からの FBX SDK 利用について

Autodesk Platform Services ページ で提供されている、Python 関連のコンポーネントには『FBX Python SDK』と『FBX Python Bindings』の2つがある。

  • FBX Python SDK

    • wheel 形式で提供されている FBX SDK の Python Binding モジュール
    • Python 3.10.x のみ対応(このバージョン以外ではインストールできない[1]
    • pip install後すぐに利用できるが、単体ではコード補完は効かない


  • FBX Python Bindings

    • FBX Python SDK をビルドするためのパッケージ
    • これを用いてビルドする FBX Python SDK のパッケージには、設定を行えばコード補完を効かせることができる
    • 任意の Python バージョンで利用可能


コンパイル済みのものとユーザーがビルドするためのもので名称が分かれており、Python のバージョン要件も異なる点に注意。すぐにでも利用したい場合は上記ページより FBX Python SDK をダウンロードし、一方、好みの環境でかつコード補完も効かせたい場合は FBX Python Bindings を使って自身でビルドする。


次章より、 FBX Python Bindings を用いて FBX Python SDK をビルドし、 VS Code でコード補完を効かせるまでの手順を紹介する。


2. ビルド要件

  • FBX SDK および FBX Python Bindings
  • C++ Compiler(Windows の場合は Visual Studio)
  • Python Interpreter(仮想環境のものでも可)
  • SIP Python Bindings Generator


また、筆者環境は以下の通り。

  • Windows 11
  • FBX SDK 2020.3.9
  • Visual Studio 2026 18.4.2(MSVC v143 Build Tools を使用)
  • Python 3.13.9
  • SIP 6.6.2


3. FBX Python Bindings の導入

Autodesk Platform Services ページ にアクセスし、FBX Python Bindings インストーラをダウンロードする。

alt text


ダウンロードしたインストーラを起動する。「I accept」を選択。
alt text


インストールパスはデフォルトのままでよい。
alt text


ぜひ README には目を通そう。「Yes」を選択
alt text


これでインストールは完了。
インストーラは閉じてよい。


4. ビルド準備

4.1. FBX SDK のインストール

FBX Python SDK をビルドするには、FBX Python Bindings だけでなく、FBX SDK も必要。
Autodesk Platform Services ページ から同じバージョンの FBX SDK を、同様の手順でインストールする。

Windows の場合、使用する Visual Studio Compiler のバージョンに合わせること。

alt text

4.2. 環境変数の設定

以下の2つの環境変数を設定する。FBXSDK_COMPILERは Windows でのみ必要な環境変数。

環境変数 概要と値の例
FBXSDK_ROOT 前節でインストールした FBX SDK のルートディレクトリ。
例: C:\Program Files\Autodesk\FBX\FBX SDK\2020.3.9
FBXSDK_COMPILER 使用する Visual Studio Compiler のバージョンを表す値。
例: vs2022


FBXSDK_COMPILERの値は、前節でインストールした FBX SDK の種類に合わせればよい。例えばFBX SDK 2020.3.9 VS2022をインストールしたのなら、vs2022を指定する。

4.3. SIP のインストール

SIP は C/C++ ライブラリの Python Bindings を生成するツール。FBX Python SDK のビルドには、バージョン 6.6.2 の SIPが必要[2]

python -m pip install --force-reinstall -v "sip==6.6.2"


ターミナルにてsip-build --helpを実行し、ヘルプが表示されることを確認しておく。


5. ビルド

以下の作業は管理者権限で行うこと。

5.1. stubファイルを生成するよう設定

stub ファイルとは、Python のモジュールについて型情報を提供するもの[3]。拡張子は .pyi。VS Code などのエディタでコード補完を効かせるために必要なファイル。

SIP のコマンドラインツールでは、ビルドするモジュールについて stub ファイルを作成するよう設定できる。具体的には、sip-buildsip-installsip-wheelにオプション --pep484-pyi を指定する。

alt text
SIP Documentation より

5.2. FBX Python SDK のビルド

筆者の場合、Visual Studio 2026 から MSVC v143 Build Tools を使用するため、予め以下を実行する[4]

"C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x64 -vcvars_ver=14.44


カレントディレクトリを、FBX Python Bindings のインストール先に変更する。

cd "C:\Program Files\Autodesk\FBX\FBX Python Bindings\2020.3.9"


SIP のコマンドラインツールは好みをのものを使用すればよいが、ここではsip-wheelを使用して、wheel 形式にビルドする。

sip-wheel --verbose --pep484-pyi


出力が停止し「The wheel has been built.」と表示されたらビルド完了。
同ディレクトリに、fbx-2020.3.9-cp313-none-win_amd64.whl が生成される。

5.3. FBX Python SDK のインストール

前節でビルドした wheel を、FBX Python SDK を使用したい環境でインストールする。

python -m pip install path\to\fbx-2020.3.9-cp313-none-win_amd64.whl


site-packagesディレクトリに以下の3つがインストールされていることを確認する。

  • fbx-2020.3.9.dist-info
  • fbx.cp313-win_amd64.pyd
  • fbx.pyi

alt text


6. VS Code でコード補完を実現する

前章の手順でインストールした場合、FBX Python SDK をインストールした Python Interpreter を VS Code で選択すれば、コード補完が既に効くようになっている。

alt text


コード補完が効かない場合、また FBX Python SDK をインストールせず使用する中でコード補完を効かせたい場合は、手動で設定する。

VS Code の設定ファイル settings.json を開き、"python.analysis.extraPaths" の項目に stub ファイル(fbx.pyi)が存在するディレクトリのパスを追記する。

"python.analysis.extraPaths": [
    "C:\\Program Files\\Autodesk\\FBX\\FBX Python Bindings\\2020.3.9\\build\\fbx"
]


7. 補足

空の FBX Scene を出力する、簡単なサンプルを示す。

test.py
from argparse import ArgumentParser
from pathlib import Path
from fbx import *

arg_parser = ArgumentParser()
arg_parser.add_argument("-o", "--output-name", type=str, required=True, help="Name of the output FBX file")
arg_parser.add_argument("--ascii", action="store_true", help="Export in ASCII format")
arg_parser.add_argument("--encrypt", action="store_true", help="Export in encrypted format")
args = arg_parser.parse_args()

# Initialize and configure the FBX SDK manager
fbx_manager = FbxManager()
ios_settings = FbxIOSettings.Create(fbx_manager, IOSROOT)
fbx_manager.SetIOSettings(ios_settings)

# Configure the output path
output_path = Path(args.output_name)
if output_path.suffix.lower() != ".fbx":
    output_path = output_path.with_suffix(".fbx")

# Initialize the FBX exporter
fbx_exporter = FbxExporter.Create(fbx_manager, "")
file_format = -1
if args.ascii:
    file_format = fbx_manager.GetIOPluginRegistry().FindWriterIDByDescription("FBX ascii (*.fbx)")
if args.encrypt:
    file_format = fbx_manager.GetIOPluginRegistry().FindWriterIDByDescription("FBX encrypted (*.fbx)")

if not fbx_exporter.Initialize(str(output_path), file_format, fbx_manager.GetIOSettings()):
    print(f"Error initializing FBX exporter: {fbx_exporter.GetStatus().GetErrorString()}")
    exit(1)

# Create a new FBX scene
new_scene = FbxScene.Create(fbx_manager, "New Scene")

# Export the scene
if not fbx_exporter.Export(new_scene):
    print(f"Error exporting FBX scene: {fbx_exporter.GetStatus().GetErrorString()}")
    exit(1)

print(f"Successfully exported FBX file to: {output_path}")

# Cleanup
fbx_manager.Destroy()


このサンプルは、-oオプションで出力ファイル名を指定し、ASCII形式で出力したい場合は--asciiオプションを指定して実行する。また、暗号化形式で出力したい場合は--encryptオプションを指定する。

以下を実行すると、カレントディレクトリにoutput.fbxという名で ASCII 形式の FBX ファイルが出力される。

python test.py -o output --ascii


FBX SDK を用いた開発の詳細は、公式ヘルプ および リファレンス を参照されたい。


脚注
  1. 公式ヘルプより Platforms supported を参照。 ↩︎

  2. 現在の最新バージョンを使用して問題ないかは不明。README に従うのが無難と思われる。 ↩︎

  3. https://typing.readthedocs.io/en/latest/guides/writing_stubs.html ↩︎

  4. https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-170 ↩︎

Discussion