Undo operations and Entity references


#1

I have a problem with my plugin and Undo operations. I have a set of custom classes which store collections of Sketchup entities. These all react to observer events of various kinds.

I have discovered that when a user hits “undo”, the references I have in my custom classes to these entities become Deleted Entity references.

Try this for yourself in the Ruby console:

  1. create a rectangle, and select the face, type temp_face = Sketchup.active_model.selection[0] into the console
  2. move one of the edges of the face. You will find that typing puts temp_face into the console will refer to the same face.
  3. now hit “Undo” form the Edit menu.
  4. type in puts temp_faceto the console again, and you will find that it refers now to a Deleted Entity.
  5. Try “Redo” and you will find that the temp_face still refers to a Deleted Entity.

All this makes it very difficult for me to track entities (which I observe with various observers) across the undo stack. In fact when the user clicks “Undo”, pretty much my whole custom entities structure gets broken.

Is there anything I can do to continue to track entities across Undo commands, or do I have to rebuild my custom classes (and observers) on every Undo (and Redo) operation? Sounds expensive to me.


#2

Actually, I realise that the above isn’t true at all! My mistake!

However, the following WILL happen:

  1. create a rectangle, and select the face, type temp_face = Sketchup.active_model.selection[0] into the console
  2. delete the face. You will find that typing puts temp_face into the console will refer to a Deleted Entity.
  3. now hit “Undo” form the Edit menu, so that the face reappears.
  4. type in puts temp_face to the console again, and you will find that it still refers to a Deleted Entity. The old entity has not “Undeleted” itself after the undo command. You will find that Sketchup has created a new entity reference to the face that was put back in from the Undo command.

… this still isn’t ideal for my purposes. I think I will still have to rebuild my objects if the user hits “Undo”.


#3

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.