从特定文件路径,相对路径,Unix可执行文件打开Blender(程序)

时间:2012-03-25 10:20:09

标签: macos executable relative-path blender-2.50

在我之前的问题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"])

结果:

  1. 在Windows中,它运行正常。
  2. 在Mac上,结果是文件已打开,但程序似乎无法打开。我觉得很奇怪。
  3. 问题:

    1. 我是否应该为搅拌机(UNIX可执行文件)添加任何扩展名以便打开它?
    2. 我是否可以通过其他方式正确打开程序,还可以使用.blend文件中的相对路径?

1 个答案:

答案 0 :(得分:0)

import os
import subprocess

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

path1 = "./"

os.chdir(path1)

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

两个blender完全打开,并且.blend文件中的相对路径正常工作:)