Blender スクリプト レンダリング画像をカメラ名を付けて保存

ファイル名にアクティブなコレクション名を追加したスクリプト(3/29追記)
GPT-4o mini
GPT-4o mini
>import bpy import os # 現在のシーンを取得 scene = bpy.context.scene # 現在のシーンのカメラを取得 camera = scene.camera # シーン名を取得 scene_name = scene.name # カメラ名を取得 camera_name = camera.name # レンダリング設定を取得 render = bpy.context.scene.render # render.filepathが設定されているか確認 if not render.filepath: print("Error: render.filepath is not set. Aborting.") else: # ファイル名を除いたパスを取得 directory = os.path.dirname(render.filepath) # 新しいパスを設定 new_filepath = os.path.join(directory, f"{camera_name}_{scene_name}.png") render.filepath = new_filepath # レンダリングを実行 bpy.ops.render.render(write_still=True)GPT-4o mini
>import bpy import os # 現在のシーンを取得 scene = bpy.context.scene # 現在のシーンのカメラを取得 camera = scene.camera # シーン名を取得 scene_name = scene.name # カメラ名を取得 camera_name = camera.name # レンダリング設定を取得 render = bpy.context.scene.render # render.filepathが設定されているか確認 if not render.filepath: print("Error: render.filepath is not set. Aborting.") else: # ファイル名を除いたパスを取得 directory = os.path.dirname(render.filepath) # 新しいパスを設定 new_filepath = os.path.join(directory, f"{camera_name}_{scene_name}.png") render.filepath = new_filepath # レンダリングを実行 bpy.ops.render.render(write_still=True)<
>render.filepathが設定されていない時は中止する。render.filepathが設定されているときはファイル名を除いたパスを取得して新しいパスとして使う設定にしてほしい . GPT-4o mini Blenderのスクリプトを修正して、render.filepathが設定されていない場合は中止し、設定されている場合はファイル名を除いたパスを取得して新しいパスとして使用するようにすることができます。以下のスクリプトを参考にしてください。 python コードをコピー import bpy import os # 現在のシーンのカメラを取得 camera = bpy.context.scene.camera # カメラ名を取得 camera_name = camera.name # レンダリング設定を取得 render = bpy.context.scene.render # render.filepathが設定されているか確認 if not render.filepath: print("Error: render.filepath is not set. Aborting.") else: # ファイル名を除いたパスを取得 directory = os.path.dirname(render.filepath) # 新しいパスを設定 new_filepath = os.path.join(directory, f"{camera_name}.png") render.filepath = new_filepath # レンダリングを実行 bpy.ops.render.render(write_still=True) スクリプトの説明 カメラの取得: 現在のシーンのカメラを取得します。 render.filepathの確認: render.filepathが設定されていない場合はエラーメッセージを表示して中止します。 パスの取得: os.path.dirname()を使用して、ファイル名を除いたディレクトリパスを取得します。 新しいパスの設定: カメラ名をファイル名として新しいパスを作成し、render.filepathに設定します。 レンダリングの実行: 最後に、レンダリングを実行します。 このスクリプトをBlenderのテキストエディタにコピーして実行することで、指定した条件に従ってレンダリングを行うことができます。<
>import bpy # 現在のシーンを取得 scene = bpy.context.scene # 現在のシーンのカメラを取得 camera = scene.camera # シーン名を取得 scene_name = scene.name # カメラ名を取得 camera_name = camera.name # レンダリング設定を取得 render = bpy.context.scene.render # 出力パスを設定 render.filepath = f"D:\\Drive - Biz\\プロジェクト\\2025\\レンダリング\\{camera_name}_{scene_name}.png" # 保存先のパスを指定 # レンダリングを実行 bpy.ops.render.render(write_still=True)
>3dソフトのblenderでレンダリングした画像の名前をカメラ名として自動で保存したい時の設定を探して . GPT-4o mini Blenderでレンダリングした画像をカメラ名として自動で保存する設定を行うには、以下の手順を参考にしてください。 スクリプトを使用する: BlenderのPython APIを利用して、レンダリング時にカメラ名をファイル名として使用するスクリプトを作成します。 スクリプトの例: 以下のスクリプトをBlenderのテキストエディタにコピーして実行することで、レンダリング時にカメラ名をファイル名として保存できます。 python コードをコピー import bpy # 現在のシーンのカメラを取得 camera = bpy.context.scene.camera # カメラ名を取得 camera_name = camera.name # レンダリング設定を取得 render = bpy.context.scene.render # 出力パスを設定 render.filepath = f"/path/to/save/{camera_name}.png" # 保存先のパスを指定 # レンダリングを実行 bpy.ops.render.render(write_still=True) 上記のスクリプトでは、/path/to/save/を実際の保存先のパスに変更してください。 スクリプトの実行: スクリプトを実行することで、レンダリングされた画像がカメラ名をファイル名として指定したパスに保存されます。 自動化: このスクリプトをBlenderの「ハンドラ」や「オペレーター」に組み込むことで、レンダリング時に自動的に実行されるように設定することも可能です。 この方法を使うことで、レンダリングした画像をカメラ名で自動保存することができます。<Gemini
>import bpy import os # 保存先のパス output_path = "D:\\Business\\プロジェクト\\2023\\レンダリング\\" # アクティブなカメラの取得 camera = bpy.context.scene.camera # カメラ名を取得 camera_name = camera.name # シーン名を取得 scene_name = bpy.context.scene.name # ファイル名を生成(カメラ名_シーン名.png) file_name = camera_name + "_" + scene_name + ".png" # 保存先のパスとファイル名を結合 file_path = os.path.join(output_path, file_name) # レンダリング設定 bpy.context.scene.render.filepath = file_path bpy.context.scene.render.image_settings.file_format = 'PNG' # レンダリング実行 bpy.ops.render.render(write_still=True) print("レンダリング完了: " + file_path)<
>3dソフトのblenderでレンダリングした画像の名前をカメラ名として自動で保存したい時のPythonスクリプトを書いて。保存するパスは「D:\レンダリング\」です。 はい、Blenderでレンダリングした画像の名前をカメラ名として自動で保存するPythonスクリプトは以下のようになります。 Python import bpy import os # 保存先のパス output_path = "D:\\レンダリング\\" # アクティブなカメラの取得 camera = bpy.context.scene.camera # カメラ名を取得 camera_name = camera.name # ファイル名を生成 file_name = camera_name + ".png" # 保存先のパスとファイル名を結合 file_path = os.path.join(output_path, file_name) # レンダリング設定 bpy.context.scene.render.filepath = file_path bpy.context.scene.render.image_settings.file_format = 'PNG' # レンダリング実行 bpy.ops.render.render(write_still=True) print("レンダリング完了: " + file_path) スクリプトの使い方: Blenderを開き、スクリプトを実行したい.blendファイルを開きます。 スクリプトエディタを開きます(画面上部の「スクリプト」タブをクリック)。 上記のPythonスクリプトをスクリプトエディタに貼り付けます。 スクリプトエディタの実行ボタン(▶)をクリックしてスクリプトを実行します。 注意点: スクリプト内の output_path 変数を、実際の保存先のパスに変更してください。 スクリプトはアクティブなカメラを使用してレンダリングします。複数のカメラがある場合は、アクティブなカメラを切り替えてからスクリプトを実行してください。 スクリプトはPNG形式で画像を保存します。他の形式で保存したい場合は、 bpy.context.scene.render.image_settings.file_format の値を変更してください。例:JPEG形式で保存する場合は 'JPEG' に変更します。 保存先のフォルダが存在しない場合は、スクリプトを実行する前に作成してください。<