UserDictionary and undo record

Hi guys!
I would like to modify RhinoObject user dictionary and I would like to let the user to undo this operation.
Basically, my code looks like this:

UInt32 recordSerialNumber = RhinoDoc.ActiveDoc.BeginUndoRecord(“UpdateUserDictionary”);
myRhinoObject.Geometry.UserDictionary.AddContentsFrom(myUserDictionary);
RhinoDoc.ActiveDoc.EndUndoRecord(recordSerialNumber);

If I hit the undo butto, right after the code was executed, Rhino simply shows a “Nothing to undo” message and, of course object user dictionary wasn’t restore to its previous state.
What am I doing wrong?

Hi @software_comas ,
As far as I know, undo does not support changes to user dictionary as mentioned in this post RhinoCommon - Removing User Data - #18 by dale

You could make a copy of your geometry, and then change UserDictionary, after use ObjectTable.Replace()

For example if your RhinoObject is a BrepObject,

UInt32 recordSerialNumber = RhinoDoc.ActiveDoc.BeginUndoRecord(“UpdateUserDictionary”);
Brep geometryCopy = myRhinoObject.BrepGeometry.DuplicateBrep();
geometryCopy.UserDictionary.AddContentsFrom(myUserDictionary);
doc.Objects.Replace(myRhinoObject.Id, geometryCopy);
RhinoDoc.ActiveDoc.EndUndoRecord(recordSerialNumber);

Thanks @Darryl_Menezes!
I’ll try your solutions ASAP! :slight_smile:

1 Like