I'm trying to run a headless Blender from inside a Python program. I intend to have Blender run another Python program after it opens a file.
I can make this work from the command line as such
D:\Documents\Programming\████████>"C:\Program Files\Blender Foundation\Blender 3.6\blender.exe" "kitchen table.blend" -b -P animate_book.py -- "./███████/███████/scripts/chapter-001.csv"
Blender 3.6.0 (hash c7fc78b81ecb built 2023-06-27 08:27:30)
Read prefs: "C:\Users\████████\AppData\Roaming\Blender Foundation\Blender\3.6\config\userpref.blend"
Read blend: "D:\Documents\Programming\█████████\kitchen table.blend"
Info: Total files 73 | Changed 29 | Failed 0
Info: Saved "chapter-001.blend"
This works as expected, opening in background mode, loading kitchen table.blend, and running the script using the custom argument after the --
However, when I try to do the same from Python I can't get Blender to digest the --python argument. Not as -P nor anything else, like --python-text.
Any insights?
I run a Python command like:
subprocess.run(['C:/Program Files/Blender Foundation/Blender 3.6/blender.exe', 'kitchen table.blend', '--background', '--python animate_book.py', '-- ' + chapter.title_filename + '.csv'])
But I get the following error:
Blender 3.6.0 (hash c7fc78b81ecb built 2023-06-27 08:27:30)
Read prefs: "C:\Users\████████\AppData\Roaming\Blender Foundation\Blender\3.6\config\userpref.blend"
Read blend: "D:\Documents\Programming\████████\kitchen table.blend"
unknown argument, loading as file: --python animate_book.py
Error: Cannot read file "D:\Documents\Programming\████████\--python animate_book.py": No such file or directory
I've looked around a bit, and found Blender doesn't recognize --python as a command line argument, but I don't seem to have the same problem? And it works from the command line already, just not from the Python subprocess.run() call?
Any thoughts appreciated.
--pythonand the scrip file name in different quotes, as shown here? $\endgroup$