User String Attributes and CTRL+Z

Hi,

I am running the following method to delete specific user string attributes:

    def clear_features(self):
        for key in self.geometry_plane[0].Attributes.GetUserStrings():
            if "feature" in key:
                self.geometry_plane[0].Attributes.DeleteUserString(key)
        self.geometry_plane[0].CommitChanges()

It works but I cannot go back and CTRL+Z does not bring the attributes back.

Is there a way to enable “history” for user attributes?

there are snippets and examples (c#) that use doc.Objects.ModifyAttributes instead of commit change…

// Make a copy of the object's attributes
    var attributes = rhObject.Attributes.Duplicate();

    // Attach our user data
    attributes.UserData.Add(userData);

    // Modify the object's attributes
    doc.Objects.ModifyAttributes(rhObject, attributes, false);

same approach in this sample

var attributes = obj.Attributes.Duplicate();
          attributes.SetUserString(SampleStringData.Key, SampleStringData.Value);
          doc.Objects.ModifyAttributes(objref, attributes, false);

but i have not tested if this makes any difference then CommitChanges()… worth trying I think.

I hope i interpreted correct - you want to support undo - not history ?

kind regards - tom

Works like a charm, thank you very much:


    def clear_features(self):

        attributes = self.geometry_plane[0].Attributes.Duplicate()
        for key in attributes.GetUserStrings():
            if "feature" in key:
                attributes.DeleteUserString(key)
        Rhino.RhinoDoc.ActiveDoc.Objects.ModifyAttributes(self.geometry_plane[0], attributes, False)

        self.geometry_plane[0].CommitChanges()
1 Like