I don’t find a way to do this in C++.
For example, with @dale’s SampleCustomGrips, I create a rectangle, edit the grips, then save the file. When I open it again and edit them, they are no longer the custom grips, but the default polyline ones.
Keep in mind that grips are not saved in a 3dm file. Rather, there are created, somewhat on the fly, when the user wants to use them.
Does does get saved in 3dm files are objects that inherit from CRhinoObject.
By design, Rhino will not save custom CRhinoObject-derived classes. This means, the CRhinoRectangleObject found in the sample you referenced, will not be saved in he file. Rather, it’s base class, or CRhinoCurveObject, will be saved.
Thus, the technique you can use to round trip custom objects, such as CRhinoRectangleObject is to attached a piece of custom user data to the object that saves with the base object. Then when Rhino reads the 3dm file, check to see if the object has your custom data and, if so, convert it back to your derived class type.
The SampleMarker SDK sample project demonstrates how to do this.
Just as a side question: is it possible to change the object mode of a CRhinoGripObject from normal to hidden and vice versa?
I tried the method ModifyAttributes but it doesn’t seem to do it (actually it is an override to “prevent” changing grip attributes). I also tried HideGrip but it doesn’t work neither.