UserData - Regression in Rhino 8

Hi there, in our plugin we set & remove a temporary UserData flag on objects to mark them for processing or not.

This works perfectly in Rhino 7 and used to work in Rhino WIP but now I am testing in Rhino 8 I am getting errors.

This is approximately the code I have

[Guid("myguid")]
public class MyFlag : UserData { 
       //I do not want it to serialize so never implemented any of the override methods. 
}

...
RhinoObject o 

var oFlag = o.UserData.Find(typeof(MyFlag));
// test for presence 
var HasFlag = oFlag != null;

// add flag
if (!o.UserData.Add(new MyFlag ())) {
     **This is the error - Add always seems to fail ** 
}

// remove 
if (!o.UserData.Remove(oFlag)) {
   // also get an error
}

Is there any way to know why Add is failing?

Is it because I am saving the UserData on the RhinoObject? If i change to RhinoObject.Geometry then i get no issues. However calling this on RhinoObject definately works in Rhino 7. Both descend from CommonObject which is where i think the UserData is stored.

Yes. User data should be attached to either an object’s geometry or an object’s attributes.

https://mcneel.myjetbrains.com/youtrack/issue/RH-48844

– Dale

1 Like

Thank you @dale I will save on geometry then. In light of this and the notes on the youtrack issue, can we add a sentence to Rhino - Plugin User Data (rhino3d.com) advising against saving data on a RhinoObject (despite its inheritance).

2 Likes