CustomCurveObject serialization?

I’m having a small problem with copying/pasting/saving/loading my customcurveobject. What should I do to make it happen ? Currently when I copy this object with command line, it works fine. Problems start whenever I try to use clipboard or when I save the file… after loading (or actually on saving), my geometry turns into LineCurve. Does this class even supports serialization ? If not, what would be a solution ?

Imports Rhino
Imports Rhino.Geometry
Imports System.Drawing

Public Class CustomObj
    Inherits Rhino.DocObjects.Custom.CustomCurveObject
    
    Public Overrides Function ToString() As String
        Return "Custom Line"
    End Function

    Sub New()
        MyBase.New(New LineCurve(New Point3d(0, 0, 0), New Point3d(1, 1, 1)))
    End Sub

    Protected Overrides Sub OnDraw(e As Display.DrawEventArgs)
        e.Display.DrawCurve(Me.CurveGeometry, Color.Aqua)
    End Sub

    Public Overrides Function ShortDescription(plural As Boolean) As String
        Return "Custom Line"
    End Function

End Class

These classes don’t serialize automatically. What we did was to store data on the object’s UserDictionary and when the document is loaded, to check the existence of said data and convert it to the custom objects.

That’s what I supposed. Thanks.
Have you noticed any problems with that approach ?

No, it seems to be working fine here.

So I ended (sort of) up with developing a custom UserData attached to CustomCurveObject. The problem is that when somehow I got it to work, I started to mess around with referencing proper user data to custom curves.

Let me explain what I did and ask some questions at the same time ;

  1. My UserData hold only one value so far, but I want it future-proof so I will stick with that rather than with UserDictionary
  2. I keep reference to my UserData in CustomCurveObject… but I don’t really know if it’s even a proper way of keeping track of that information which is stored in the underlying Curve.
  3. Let’s say I have a curve with some UserData - is it also duplicated when I call Duplicate on the curve ? (or is it mysteriously referenced only to a new curve, or maybe it is ADDED - vide next point)
  4. In the UserDataList documentation it is stated :

Add : If the userdata is already in a different UserDataList, it will be removed from that list and added to this list.
Why oh why McNeel ppl you make my life so hard :wink:

  1. Does it mean that each GeometryBase holds it’s own UserDataList, or is it somehow stored in the Document, or Shared among GeometryBase classes ?
  2. If I want to replace a value in the Curve.UserData from the level of MyCustomCurve (has MyData value set previosly to MyCustomCurve.UserData.Find(CustomUserData) :
    Me.Geometry.UserData.Remove(MyData)
    MyData = New MyCustomCurve(Value)
    Me.Geometry.UserData.Add(MyData) 

Does it even make sense ?

I think you make your life difficult by using user data, instead of using the user dictionary. We’ve made some extensive plugins with data on objects and have never needed the added complexity of user data, everything we want to do can be accomplished with the dictionary.

If you also switch to the dictionary, I think you find that all subsequent problems will go away…