Skip to main content
 首页 » 编程设计

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

2024年11月24日13傻小

我目前正在打开 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 模块 rhino3dm 和 compute_rhino3d 直接在 Python 中使用 Rhino 的计算函数(无需打开 Rhino)。

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