C++ How to add custom snap points to custom Rhino object

Hello,

Is this possible within the Rhino 5 C++ SDK? I have my custom curve object and I want to add custom points in such a way that they appear as construction points when Osnap is on.

Many thanks,
Pablo

@mikko, any ideas here?

Seems to me this should be possible by overriding CRhinoObject::SnapTo for the custom object. You’ll probably want to call CRhinoCurveObject::SnapTo in it to get the basic curve snapping.

Thank you @mikko , this looks indeed the way to go.
Just to know, is there any sample showing how to use it? (mainly CRhinoSnapContext and CRhinoSnapEvent)? @dale?

Pablo

Hi @pagarcia,

The suggestion was that if you have a custom object that derives from CRhinoCurveObject then override the CRhinoObject::SnapTo virtual function. Picking will automatically use the “snap to” results.

Does this make sense?

– Dale

Hi @dale,

Just a question about the actual use of it. Imagine I want to add ON_3dPoint A to the snapping points of the object. How to do it? I tried this (assume A is globally known):

bool CRhinoCurveObject::SnapTo(const CRhinoSnapContext& snap_context, CRhinoSnapEvent& snap_event) const 
{
       return snap_context.SnapToPoint(A);
}

Pablo

Hi @pagarcia,

Call base class first, per @mikko suggesions.

bool CMyCurveObject::SnapTo(const CRhinoSnapContext& snap_context, CRhinoSnapEvent& snap_event) const 
{
  bool rc = CRhinoCurveObject::SnapTo(snap_context, snap_event);
  if (!rc)
  {
    // todo...
  }
  return rc;
}

– Dale

Hello,

Is it possible to do something similar from RhinoCommon?

Márton