python - 如何使用 Python 脚本与打开的 Rhino3D 应用程序交互

标签 python python-3.x rhino3d

我目前正在打开 Rhino 并在外部 python 脚本中使用 subprocess.call() 运行 Rhino 命令行。

rhinoPath = "C:\\Program Files (x86)\\Rhinoceros 5\\System\\Rhino4.exe"
rhinoCommandFilePath = "Z:\\Arkangus\\2019\\RhinoCommand.txt"
scriptCall = "_-ReadCommandFile {0}".format(rhinoCommandFilePath)
callScript = '"{0}" /nosplash /runscript="{1}" /runscript="_-Exit"'.format(rhinoPath, scriptCall)
subprocess.call(callScript)

但是,这意味着每次运行脚本时都打开 Rhino,然后关闭它。

有没有办法检查 Rhino 是否已经打开,如果是的话,直接在 Rhino 中运行 RhinoCommand 文件?

我不是在寻找 Rhino 和 Python 之间的管道。

谢谢!

最佳答案

检查 Rhino 是否已经打开(注意:这只是对我的问题的部分回答):

Checking if program is running programatically

import psutil

def is_rhino_open():
    for pid in psutil.pids():
        p = psutil.Process(pid)
        if p.name() == "Rhino5.exe":
            print ("Rhino5 is running!")

其他方式:通过 CPython3.x 模块 rhino3dmcompute_rhino3d 直接在 Python 中使用 Rhino 的计算函数(无需打开 Rhino)。

https://discourse.mcneel.com/t/run-script-from-windows-command-prompt-with-open-rhino/80736/2?u=gabriel.taquet

关于python - 如何使用 Python 脚本与打开的 Rhino3D 应用程序交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55238627/

相关文章:

python - Rhino python 代码生成

c# - 此方法的参数预期是什么?

python - 基于值的 Seaborn 条件颜色

python - 提供 Python 脚本的网络服务器

python-3.x - 只批处理读取/将最后一张图像保存在文件夹中

python - 如果还有其他输入意味着出了点问题,我应该如何结束if-else block ?

python - 使用 'pass' 作为字典关键字

c# - Rhinoscript 将 Python 对象移动到 C#

python - append 到列表列表

python - AUTO_INCREMENT 在 sqlite 问题与 python