C++: Deriving from CRhinoObject

is it possible in principle to create a custom Rhino object by deriving from CRhinoObject? Are there any common pitfalls to think about when doing so? The idea would be to implement a custom mesh object. Would it be better to derive from CRhinoMeshObject? I would also derive from ON_Mesh to represent the geometry.

Yes, it is possible to create custom objects by deriving from CRhinoObject. If all you want is a custom version of something we already have, like a mesh, then it is best to derive from that specific runtime object. This will save you a ton of work. In the case of a mesh, you would derive from CRhinoMeshObject.

Note that Rhino will not serialize a custom object. Thus, you will need to store all of your custom data as user data on your object. Your user data will serialize with with the base Rhino runtime object.

Here is a simple example of a custom object. This one derived from CRhinoGetPoint, but you should get the idea.


Hi Dale,

I have created some custom objects that I would like to derive directly from CRhinoObject. However, I did not succeed doing so if the object were derived from CRhinoObject. Instead I have them derived from CRhinoPointObject.

The problems I have when they are derive directly from CRhinoObject are:

  • The custom objects are not part of the document object list
  • The Draw() method is not called
    In general, the custom objects do not seem to be added to the object list and I did not see the same problem when they are derived from CRhinoPointObject.

Do you have any sample code that shows the custom object derived from CRhinoObject?



No I don’t.

Why do you want to derive a new object from CRhinoObject? These objects will not serialize, which is a big drawback…

I have different types of custom objects; measure device objects, GD&T objects, color legend objects and they are not related to rhino point objects or surface objects at all. That is why I do not want them derived from CRhinoPointObject.

About the serialization, those objects do not serialize. I do have other objects which are derived from ON_UserData and they are added to the above mentioned objects as the user attributes which are serialized.

When deriving the classes from CRhinoObject, everything seems to work fine until the objects are added to the document which always fails. I am wondering if this is a known issue or not. If yes, I will stop trying to solve the issue.



Not having tried deriving a class directly from CRhinoObject, I cannot easily answer this. But, it your derived class is not fully implemented or implemented correctly, I can see what CRhinoDoc::AddObject would fail. What object type does your CRhinoObject derived class return (ObjectType)? What type of geometry does your virtual Geometry() override return?

Not everything you see on the screen needs to be in the document. The Gumball is a good example of this, as it is just drawn using a display conduit.

Also, the Rhino SDK has a CRhinoPhantomObject that you can derive from if you want to add stuff to the document that does not serialize.

Thanks Dale. I will try to use CRhinoPhantomObject.

I can post a sample code of my object if you are curious how I implemented it.



Hi Dale,

Just to keep you posted on the issue. I have tried to derive my custom object from either CRhinoPhantomObject or CRhinoProxyObject, the result is the same as derived from CRhinoObject. I fails when adding the object to the doc.

Is it possible to access to the CRhinoPointObject.cpp some how? Just want to compare with what I have.



Here is an example that works: