Copy pasting custom rhino mesh object subclasses

As the title suggests, I have a CRhinoMeshObject with alot of its own bells and whistles. When I select it and then copy/paste it, I get back only the mesh (base class). How do I handle copy pasting of my object?

Thanks in advance.

As far as I can recall, the copy-pasting will call DuplicateObject() which is implemented as follows in the ON_OBJECT_IMPLEMENT macro (you should use this macro if you don’t already, see the custom object example code!):

ON_Object* cls::DuplicateObject() const {cls* p = new cls(); if (p) *p=*this; return p;} 

As you can see, a new object is created with the default constructor cls* p = new cls(); and then the assignment operator is used *p = *this

That means that you need to implement the assignment operator

CYourObject& operator =(const CYourObject&); // header

CYourObject& CYourObject::CYourObject::operator =(const CYourObject& src) 
// todo: create a copy using src as input

Edit: might this have anything to do with the fact that my object type still shows up as “closed mesh” in Rhino despite it being custom?

I’ve tried all of the above with no luck unfortunately. The assignment operator is never called on paste

I added the duplicate rhino object method below when it didn’t work with just the operator.

ON_OBJECT_IMPLEMENT(CRhinoSuperDMeshObject, CRhinoMeshObject, "....");

CRhinoSuperDMeshObject::CRhinoSuperDMeshObject(const CRhinoSuperDMeshObject &cs)
  : CRhinoMeshObject(cs)
  *this = cs;

CRhinoSuperDMeshObject &CRhinoSuperDMeshObject::operator =(const CRhinoSuperDMeshObject &cs)

  return *this;

CRhinoObject *CRhinoSuperDMeshObject::DuplicateRhinoObject() const
  auto ret = new CRhinoSuperDMeshObject();
  *ret = *this;

  return ret;

Also I can’t find this custom object example code anywhere. Can you link me?

Hi @gccdragoonkain,

Here is one from the samples repo:

– Dale

Very helpful! Thanks. I see PromoteRhinoPointObjectToMarkerObject answers another question I had regarding saving data to a file.

I’m assuming the above sample marker works properly with copy/paste?

I think so - you might try…

– Dale

Indeed it does… odd. I’ll post back here when I find out what I’m missing.

Okay. Wow… so I wasn’t expecting this.

The answer… lies in the fact that OnEndOpenDocument is called after a paste. Then PromoteRhinoPointObjectToMarkerObject is called for the new point when it is found.

Very counterintuitive. But the good news is I’ll be able to implement copy/paste and file saving/loading with the same code.

Hi @gccdragoonkain,

CopyToClipboard/Paste is basically a file I/O operation. This is why the call to OnEndOpenDocument is triggered.

– Dale

1 Like