Hey guys,
I want to do some customized moves through Rhino Common when the user edits geometries.
I started by subscribing to RhinoDoc.AddRhinoObject, but it fires whenever a geometry gets modified - so when I edit multiples simultaneously, the calculation has to be done many times.
Then I tried to collect them together and run the calculation only once by giving a short Task.Delay(), then I noticed this falls off the undo record: when the user is unhappy about the result he/she has to undo twice to get back to the last step (user’s manual move and my customized follower). (I also tried RhinoApp.Idle(), same result).
The closest I’ve got was smuggling a RhinoApp.RunScript(“_Undo”, false); right after the process, it works fine but the “Redo” got ruined through this.
So, does anyone have any suggestions? Many appreciations!
Subscribe to the Idle event and execute your logic there.
In other words, when editing multiple geometries at the same time, is there an event firing right after the last object is replaced?
Tried, won’t work for a seamless experience: subscribing to Idle will fall out of the Undo record of that step, so if the user is not happy about the step, they need to undo it twice to get back. (user’s step and mine)
You can first check which events are fired in which order using this helper class:
Batching edits via the Idle
event handler should do the trick. If you need custom undo logic, you can hook it up to Idle
as well:
And here you can see how to have a proper redo as well:
Oh - this helper class is very helpful! Thank you for showing this to me.
I tried the OnIdle trick in the post you quoted, unfortunately, it still falls out of the original undo recording. It became its own undo step which ends up requiring a double undo-click, too.
But I finally made it work by shoving an AddCustomUndoEvent inside the function that subscribed to RhinoDoc.AddRhinoObject. So we can call this a closed case anyway