在我之前的问题Open a file from a specific program from python中,我了解了如何使用 subprocess 以使用.blend
此代码从特定文件路径打开程序(Blender)——好吧,一个特定文件。
import os
import subprocess
path = os.getcwd()
os.system("cd path/")
subprocess.check_call(["open", "-a", os.path.join(path, "blender.app"),"Import_mhx.blend"])
在论坛上一个人的帮助下,我想在.blend
文件中使用相对路径,所以我以这种方式更改了代码(对于 Windows)
import os
import subprocess
# This should be the full path to your Blender executable.
blenderPath = "/cygdrive/c/Program Files/Blender Foundation/blender-2.62-release-windows32/blender.exe"
# This is the directory that you want to be your "current" directory when Blender starts
path1 = "/Users/user/Desktop/scenario/Blender"
# This makes makes it so your script is currently based at "path1"
os.chdir(path1)
subprocess.check_call([blenderPath, "Import_mhx.blend"])
对于 Mac,
import os
import subprocess
path = os.getcwd()
os.system("cd path/")
print (path)
# This should be the full path to your Blender executable.
blenderPath = path + "/blender.app/Contents/macos/blender"
# This is the directory that you want to be your "current" directory when Blender starts
path1 = "/Users/user/Desktop/scenario/Blender"
# This makes makes it so your script is currently based at "path1"
os.chdir(path1)
subprocess.check_call([blenderPath, "Import_mhx.blend"])
结果:
- 在 Windows 中,它工作正常。
- 在 Mac 上,结果是文件打开了,但程序似乎没有打开。我认为这很奇怪。
问题:
- 为了打开它,我应该为搅拌机(UNIX 可执行文件)放置任何扩展名吗?
- 有没有其他方法可以让我正确打开程序,但也可以在
.blend
文件中使用相对路径?