2

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!

Arkangus
  • 116
  • 8
  • 1
    have you looked here https://developer.rhino3d.com/guides/rhinopython/? – chris Mar 19 '19 at 10:24
  • 1
    Yes, but if I'm correct rhinopython is to be used within rhino. I was probably not clear enough, I want to run the python script externally from Rhino. – Arkangus Mar 19 '19 at 10:30
  • Have you seen https://github.com/mcneel/rhino.inside/tree/master/CPython? It might help. – Luis E. Fraguada Apr 17 '19 at 11:58
  • I had not, thanks for the link! I will take a look. I found compute_rhino3d and rhino3dm meanwhile though, will update my answer accordingly. – Arkangus Apr 25 '19 at 08:43

1 Answers1

1

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

Arkangus
  • 116
  • 8