简体   繁体   中英

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.

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.

Is there a way to check if Rhino is already open and run the RhinoCommand file directly into Rhino if it is the case?

I am not looking for a pipe between Rhino and Python.

Thank you!

To check if Rhino is already open (Note: this is only a partial answer to my issue):

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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