【发布时间】:2012-08-23 02:39:47
【问题描述】:
在我之前的问题Open a file from a specific program from python 中,我发现了如何使用子进程来打开一个程序(Blender)——嗯,一个特定的.blend 文件——从带有此代码的特定文件路径。
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"])
对于the help of a guy at a forum,我想在.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文件中的相对路径?
【问题讨论】:
标签: macos executable relative-path blender-2.50