Exit command not working

If I run this inside of Rhino, it will close:

import rhinoscriptsyntax as rs
def exit():

– Dale

Thanks for trying to deal with this problem.

When running the PythonScript inside Rhino, everything works perfectly.

But when using an external python and a python subprocess to open Rhino, the problem appears. I have attached some py files above. If you have time, you could try ro run subprocess.py to see what is happening. (only change the paths)

Thanks in advance.

Dear David Andres Leon,
Unfortunately, I did not manage to “exit” Rhino using an external python(opens Rhino and runs a rhno python script) . Even if the command is written in the command line of Rhino, it is not executed. If you have time, could you please make a try with the files that i attached below. ? Thanks in advance! The files are some comments above…

Dear all,

I am also very (to say the least) interested in seeing that working.
I am not currently able to fully automate the use of Rhino from Python since Rhino will not close.

Here is a simple text file that I drag & dropped into my open Rhino application, with the results.

I had various attempts at this, none working when there is a file involved (the Exit command will work when typed directly in the Rhino command line).

Notice that when typed directly in the command line, ‘_-Exit’ directly closes the application.
However, when scripted (through the text file), the “Save changes […]” appears.

Best regards,
Gabriel Taquet

RhinoCommandFile.txt (140 Bytes)

You need one more _Enter

I wish that was it!

RhinoCommandFile.txt (189 Bytes)

Put the _No and _Enter on the same line as your -_Exit:

_Point 0 _Enter
-_Exit _No _Enter

Still not. You are also drag and dropping the file?

No, I just used the Macro Editor to run the macro.

Is having the macro in a text file necessary for your use case?


My complete process is the following:

  1. My python package creates various shapes
  2. A ‘rhino command file’ as shown previously is written by python in order to export the shapes to Rhino and, for example, export it as IGES.
  3. Python uses the subprocess module to call Rhino with the command file as argument.

So while preparing snippets to show, I ran into an interesting behavior, coherent with the previous attempts.
Here are two python snippets, which I am running from pycharm.
The first one uses an intermediary command file, while the second one does not.

With file

import subprocess

RHINO_PATH = r"Rhino.exe"

instructions = "_-Point 0 _-Enter\n" \
               "_-Exit _-No _-Enter\n"

filepath = "RhinoCommandFile.txt"
with open(filepath, "w") as fp:

rhino_script = f"_-ReadCommandFile {filepath}"
call_script = f'"{RHINO_PATH}" /nosplash /runscript="{rhino_script}"'


Without file

import subprocess

RHINO_PATH = r"Rhino.exe"

instructions = "_-Point 0 _-Enter\n" \
               "_-Exit _-No _-Enter\n"

call_script = f'"{RHINO_PATH}" /nosplash /runscript="{instructions}"'


With the file, same result as previously.


Without the file, well, I was not able to screenshot it since it works.

Unfortunately that does not solve my problem, since when my set of instructions becomes too large I get FileNotFoundError: [WinError 206] The filename or extension is too long.

Thank you for persisting in describing your problem. I now see how you intend to use this.

I see that indeed the _-Exit does not work, and that any commands after it in the command file do not work.

Note though that you write _-Enter (dashed version), while it should be just _Enter.

@taquet I have logged a bug for this: RH-59098.

Thank you @nathanletwory!

Right, I sort of over-dashed everything there!
Same thing with “_-No” which is even not recognized, I forgot to correct it before posting, should be “_No”.

Thanks again

Yup, I fixed that up in my own tests an the bug report (:

RH-59098 is fixed in the latest WIP

Thank you Brian.

To be honest, I’d have liked to see that working with R6. I have read the related discussion on Youtrack though and I get it. I might come back if it becomes very blocking!

Is there any news about that?
Because I still have this problem randomly with rhino 7.
I start rhino from the command line, open a file, run a python script,that ends with an exit:

rs.Command("-_Exit _No _Enter")

but it seems that closing rhino is a problem , the crazy thing is that sometimes it works and sometimes it doesn’t.

Hi @Pitti,

Does this work?

import ctypes
import Rhino
import scriptcontext

def test_exit_without_saving():
    scriptcontext.doc.Modified = False
    hWnd = Rhino.RhinoApp.MainWindowHandle()
    ctypes.windll.user32.PostMessageW(hWnd, 0x0010, 0, 0)

– Dale

It seems to work, but the problem appears only occasionally, I also want to test it with multiple instances of rhino open.
I thank you for now and will keep you updated. :wink: