0
在我剛纔的問題,Open a file from a specific program from python,我發現瞭如何使用子爲了打開一個程序(攪拌機)—好,特定.blend
文件—從具有此代碼的特定文件路徑。打開攪拌機(程序)從一個特定的文件路徑,相對路徑,Unix的可執行
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
文件內的相對路徑?