リファレンス / 3ds Max / MaxScript チートシート

ファイル・パス

  • 3ds Max
  • MaxScript
  • チートシート
MaxScript チートシート の章一覧

ファイルとパスの操作です。ダイアログでパスを得るテキストを読み書きするシーン/外部フォーマットを入出力する の3系統に分けて収録します。

パスをダイアログで取得する

getOpenFileName caption:"開く" types:"画像(*.jpg)|*.jpg|全て|*.*|"
getSaveFileName caption:"保存先"
getSavePath caption:"フォルダを選択"     -- フォルダだけ選ばせる
  • いずれもキャンセルすると undefined を返します。⚠️ 必ず undefined チェック してから使います。

パス文字列を分解・組み立てる

p = "c:/proj/scene_v003.max"
getFilenamePath p       -- "c:/proj/"(フォルダ)
getFilenameFile p       -- "scene_v003"(拡張子なしのファイル名)
getFilenameType p       -- ".max"(拡張子)
pathConfig.appendPath "c:/proj" "tex.png"   -- パス結合 → "c:/proj\tex.png"

フォルダ・ファイルの存在確認と一覧

doesFileExist "c:/a.max"          -- ファイル/フォルダの有無
makeDir "c:/out" all:true         -- フォルダ作成(親ごと)
getFiles "c:/tex/*.jpg"           -- 条件に合うファイル一覧(配列)
getDirectories "c:/proj/*"        -- サブフォルダ一覧
deleteFile "c:/tmp.txt"           -- ファイル削除

テキストファイルを書く / 読む

-- 書き込み
f = openFile "c:/log.txt" mode:"w"
format "処理開始: %\n" (localTime) to:f
close f

-- 1行ずつ読む
f = openFile "c:/log.txt"
while not (eof f) do print (readLine f)
close f
  • ⚠️ openFile の後は 必ず close します。閉じ忘れるとファイルがロックされたままになります。

シーンファイルの入出力

loadMaxFile "c:/scene.max"               -- 開く
saveMaxFile "c:/scene.max"               -- 保存
mergeMaxFile "c:/lib.max"                -- 別シーンを現在のシーンに統合
resetMaxFile #noPrompt                   -- 新規シーン(確認なし)
holdMaxFile()  /  fetchMaxFile()         -- 一時保存 / 復帰

外部フォーマット(FBX / OBJ など)

importFile "c:/a.fbx" #noPrompt          -- 確認ダイアログなしでインポート
exportFile "c:/out.fbx" #noPrompt selectedOnly:true   -- 選択のみエクスポート
  • #noPrompt設定ダイアログを出さず に処理します。バッチ処理の定番です。
  • FBX の細かい設定は FBXExporterSetParam / FBXImporterSetParam で行います。

落とし穴まとめ

  • パス取得系はキャンセルで undefined。必ずチェックする。
  • openFileclose とセット。閉じ忘れに注意。
  • バッチ処理では #noPrompt でダイアログを抑止する。
  • mergeMaxFile は同名ノードの扱い(リネーム/置換)を引数で制御できる。

関連

← MaxScript チートシート へ