Prevent users to get back erased entity

I currently writing a tool which have to use intersect_with method then after that delete the line which created. But after i’'ve delete the intersection line I found that when I press ctr + z, lines that already delete area coming back. I don’t want users to see intersection lines in the process. Is there a way to prevent lines coming back?

Perhaps an expert will correct me, but I think the answer is no.

Every operation is added to the undo stack, both for the GUI and for Ruby. Ctrl-z undoes the last operation on the stack. I don’t think there is a way to block undo and the Ruby API doesn’t provide access to the stack.

1 Like

I assume you are doing other operations beside #intersect_with. You can wrap all this methods into one operation which visible in unto stack, so the user will not see “Undo erase” or other operation individually, but all at once.

In some cases after you collected the necessary data about the geometries created then you can use #abort_operation to make the previous operation “un-happened” …

Check this methods:

The #start_operation method is used to notify SketchUp that a new operation (which can be undone) is starting. ( take a look especially the last parameter )

The #commit_operation method commits an operation for undo.

The #abort_operation method aborts the current operation started with the start_operation method.

2 Likes

I agree with @dezmo, a tool should always wrap all it’s subtasks in a single undo operation.

1 Like

You can add an undo observer to your model if you want to take some action after an undo. For example: something like updating an inspector show the number of edges in the model.

Be very careful though not to do anything that would affect the undo stack. I had some code in an undo observer once which updated an inspector. It contained a bug where inadvertently changes were made to the model. That resulted in a very frustrating user experience.

@dezmo @slbaumgartner @DanRathbun @Neil_Burkholder Thanks you guys a lot! I will work on what you have suggested.