Exit command not working

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?

Yes.

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:
    fp.write(instructions)

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

subprocess.call(call_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}"'

subprocess.call(call_script)

With the file, same result as previously.

image

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.DocumentModified(False)
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)
    
test_exit_without_saving()

– Dale

@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: