2012-03-25 83 views
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"]) 

结果:

  1. 在Windows中,它工作正常。
  2. 在Mac上,结果是文件已打开,但程序似乎未打开。我认为这很奇怪。

问题:

  1. 有,我应该为了地方搅拌机(UNIX可执行文件)才能打开任何延期?
  2. 有没有其他方法可以做到这一点,以便正确打开程序,但也能够使用.blend文件内的相对路径?

回答

0
import os 
import subprocess 

blenderPath = "./blender.app/Contents/MacOS/blender" 

path1 = "./" 

os.chdir(path1) 

subprocess.check_call([ blenderPath, "Animation.blend"]) 

两个搅拌机打开完美,.blend文件工作确定内部相对路径:)