【问题标题】:Opening Blender (a program) from a specific filepath, relative paths, Unix executable从特定文件路径、相对路径、Unix 可执行文件打开 Blender(程序)
【发布时间】: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"])

结果:

  1. 在 Windows 中,它可以正常工作。
  2. 在 Mac 上,结果是文件已打开,但程序似乎没有打开。我觉得这很奇怪。

问题:

  1. 我应该为搅拌机(UNIX 可执行文件)放置任何扩展名以使其打开吗?
  2. 有没有其他方法可以让我正确打开程序,同时还能使用.blend 文件中的相对路径?

【问题讨论】:

    标签: macos executable relative-path blender-2.50


    【解决方案1】:
    import os
    import subprocess
    
    blenderPath = "./blender.app/Contents/MacOS/blender"
    
    path1 = "./"
    
    os.chdir(path1)
    
    subprocess.check_call([ blenderPath, "Animation.blend"])
    

    两个搅拌器都可以完美打开,.blend 文件中的相对路径可以正常工作:)

    【讨论】:

      猜你喜欢
      • 2012-02-26
      • 2013-05-28
      • 1970-01-01
      • 2014-04-04
      • 2014-11-24
      • 1970-01-01
      • 2014-09-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多