简体   繁体   English

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

[英]How to interact with open Rhino3D application using Python script

I am currently opening Rhino and running Rhino command lines using subprocess.call() in an external python script.我目前正在打开 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)

However, it means opening Rhino everytime I am running the script, and closing it after.但是,这意味着每次运行脚本时都打开 Rhino,然后关闭它。

Is there a way to check if Rhino is already open and run the RhinoCommand file directly into Rhino if it is the case?有没有办法检查 Rhino 是否已经打开并将 RhinoCommand 文件直接运行到 Rhino 中(如果是这样的话)?

I am not looking for a pipe between Rhino and Python.我不是在寻找 Rhino 和 Python 之间的管道。

Thank you!谢谢!

To check if Rhino is already open (Note: this is only a partial answer to my issue):检查 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!")

Other way: use Rhino's compute functions directly from within Python (no need to open Rhino) with the CPython3.x modules rhino3dm and compute_rhino3d .其他方式:直接从 Python 中使用 Rhino 的计算函数(无需打开 Rhino),并使用 CPython3.x 模块rhino3dmcompute_rhino3d

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM