exit, break, end, kill, die, abort, raise, rescue, abort_operation…???
Its hard to know what is the appropriate way to stop execution of a plugin script. I must be missing something because this seems so basic but yet could not find much on the topic here or in the wild.
There’s a detailed discussion here but there seems to be disagreement between Dan and Tig about if
exit is the right approach or return nil.
There’s tons on plain old Ruby commentary like here but some of these methods bugsplat SU.
So… using the
UI.inputbox as an example where you might want to give a user a side exit. I’m using
abort_operation because it is at least mentioned in the API but it does not seem to work as expected because the subsequent code in the script WILL be executed.
def some_script() Sketchup.active_model.start_operation('Some Script', true) response = UI.inputbox("Question?", "", "Please tell me!") # catch "Cancel" button clicks if(response == false) Sketchup.active_model.abort_operation end #some code I would like to NOT run if Cancel has been selected print "What are you doing here?\n" #some more code I would like to NOT run if Cancel has been selected print "I said go away!\n" Sketchup.active_model.commit_operation end #def