I’m working on some very long Rhinoscripts which automate madCAM toolpath generation.
I’d like to include error checking and have my scripts stop automatically when the required objects or layers don’t exist in the current Rhino document.
I’ve searched extensively and can only find the Exit Sub command but I need an “Exit Script” command.
I suppose I could change all of my Sub procedures into Function procedures and have them return a Boolean success/fail value to the Main procedure, then surround each function call with an if/then conditional which would exit Main on an error.
But this seems a bit clunky. Is there not an easier way to exit a Rhinoscript?
Typically your script structure would be like this:
Call Main()
Sub Main()
[do something]
If <condition not met> then Exit Sub
End Sub
So only “Main” would be called and the errors/exiting would be checked there. All other Functions or Subs should communicate the condition status via some variable to the Main Sub so you can exit form there.
Not sure if this is related but you may check the special function in RhinoScript OnCancel for some cleanup possibilities while error happens or user cancels the script.