To cancel save

I have commands to start edit and stop edit.

After the start edit is clicked, the model is modified.

If the user clicks the save button, I would like to cancel the save as it is in the middle of edit mode.

how do I cancel the save?
or is there any other way to avoid the saving of the file which is at an unacceptable state?

Is your question about modifying a script? If so, you should change the topic to Scripting so more scripters and developers see it. Also post any relevant portions of your script.

No. it has nothing to do with scripting…

it is general programming…

step1: start edit command
step2: edit model
step3: save -> this needs to be checked because it is invalid to save with the modified model as the stop edit command has not been clicked. so a warning needs to be given and the save cancelled.

the question is how do i interfere with the save to cancel it. Hope i am clear.

Valid steps=>
step1: start edit
step2: edit model
step3: stop edit
step4: save

@dale any ideas?

Hi @HepChan

This is not possible.

– Dale

1 Like

I think this would be a good feature to add.

It would be really helpful.

@HepChan – I had a similar issue that I had to solve to avoid corrupted data that is being serialized during save. The way I have solved it is by creating static variable flags that I can check to determine the state of my application, and then using those flags to hinder the save process using message boxes and while loops with Thread.sleep to prevent the saving from occuring until after the critical process is finished. So, for your case, I would recommend:

  • On StartEdit, set a bool flag “EditingInProcess” to true
  • On BeforeSave, check the EditingInProcess flag. There are a couple ways to handle this, but the simplest is this: While true, use MassageBox.Show(“Editing is in process, please complete and Retry.”). When the user hits the “Retry” or “OK” button, the EditingInProcess flag gets checked again, and if the user has not finished editing, the messagebox shows again
  • On StopEdit, set EditingInProgress to false
  • User hits OK and saving thread is allowed to continue

You can do some advanced stuff like just showing a messagebox with “File will be saved when editing is complete” and just do a System.Threading.Thread.Sleep inside the while loop, but your setup may vary so use with caution. I use thread sleep but with a limit that transitions to a manual retry model after a certain amount of time to prevent long, locked up states with no feedback.

Hope this helps someone in the future, even if this is no longer an issue for the OP.


WOW!! a reply after 5 years.
Thanks @marcsyp

Can you provide a sample code please.

Would be really good if it is implemented into Rhino rather than having to do a workaround