Setup a simple relation between objects and undo behavior

I have to develop a plugin that is able to create and mantain a simple relation between objects.
More in dept, I want to create a surface (let’s call it “S”) using 2 input curves (let’s call them “C1” and “C2”).
It doesn’t matter how “S” is created but, at the time of its creation, I automatically add information about all the obejcts involved in the operation (and some extra parameters) inside all objects user dictionaries.
Now I’m able to update the “S” surface if one or both curves “C1” and C2" are modified someway, even if the curves are modified by another command.
Everything is working fine except when I’m going to undo the operation: it looks like the “S” surface update is not saved inside Rhino undo stack.
I tried to use commands like BeginUndoRecord/EndUndoRecord, wrapping surface updating, but it seems I get another undo entry in Rhino undo stack: I have to press undo twice to come back to the original document status.
Is there some way to “merge” all the operations in a single one, so that undoing them requires just a single “undo” execution?
Do you know a better/different way to setup a relation like the one I need?
Thanks a lot.


It sounds like the Record History functionality.

Thanks, @menno!
I have to admit I don’t know this feature very well…
Anyway, it looks like the Record Histoy has some limitations that make it not suitable to my needs: it looks like the Record History stops working if you just move one of the objects involved in recorded command.
Is this right?
Is there a workaround?
Thanks again!

Only when objects get “destroyed” is the history broken. If you look at the link I posted above there is a short movie illustrating the functionality: from several curves a lofted surfaces is created. Then one of the curves is moved and the surface adapts itself to the new situation.

Yes, @menno. You’re right.
Long story short, I think I need something easier to use (by our end users). Please believe me, our users are not so skilled and really appreciate tools that are really really easy to use…
Thanks again!

PS Record History is broken if I move the resulting surface. That’s not good for me.

Maybe you can use RhinoDoc.AddCustomUndoEvent instead of BeginUndoRecord/EndUndoRecord? But be aware you should also support Redo after Undo.

I already use custom undo / redo events to keep my plugin data in sync and I’m not sure that’s the right solution.
Let’s approach this from a different perspective.
As far as you know, if my code modifies objects geometries and objects user dictionaries inside a single command, they (geometries and user dictionaries) should be restored “at once” after performing a single undo operation, right?
Or, maybe, do I need to do something more to restore user dictionaries statuses?