如何使用Python脚本与开放的Rhino3D应用程序进行交互

问题描述 投票:2回答:1

我正在打开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是否已经打开并且如果是这样的话,直接将RhinoCommand文件运行到Rhino中?

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

谢谢!

python python-3.x rhino3d
1个回答
1
投票

检查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

© www.soinside.com 2019 - 2024. All rights reserved.