Get point on surface using c++

Hello there, I want to make an script in c++ for Rhino 5 in order to let the user select a point on a surface and then get the coordinates of this point. I have looked for code but I havent found anything. And I was wondering if someone knows a way to do this.

Thank you

You might want CRhinoViewport_VP_GetFrustumLine, ON_Brep_GetClosestPoint and ON_Intersect_CurveBrepParameters (or their surface equalivent).

Hi @f.leon.marquez95,

Your command’s RunCommand method might look something like this:

CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
{
  // Prompt the user to select a surface (e.g. Brep face)
  CRhinoGetObject go;
  go.SetCommandPrompt(L"Select surface");
  go.SetGeometryFilter(CRhinoGetObject::surface_object);
  go.GetObjects(1, 1);
  if (go.CommandResult() != CRhinoCommand::success)
    return go.CommandResult();

  // Get the selected Brep face
  const CRhinoObjRef& obj_ref = go.Object(0);
  const ON_BrepFace* face = obj_ref.Face();
  if (nullptr == face)
    return CRhinoCommand::failure;

  // Pick a point that is constrained to the Brep face
  CRhinoGetPoint gp;
  gp.SetCommandPrompt(L"Pick location on surface");
  gp.Constrain(*face);
  gp.GetPoint();
  if (gp.CommandResult() != CRhinoCommand::success)
    return gp.CommandResult();

  ON_3dPoint point = gp.Point();

  // Print results
  ON_wString point_str;
  RhinoFormatPoint(point, point_str);
  RhinoApp().Print(L"Surface point = %s\n", static_cast<const wchar_t*>(point_str));

  // Optional - add to the document
  context.m_doc.AddPointObject(point);
  context.m_doc.Redraw();

  return CRhinoCommand::success;
}

– Dale

Thank you very much, I could find a point. And in case i would like to display axis as if i were executing extractIsocurve. Would it be a way to do this?

Thank you

Hi @f.leon.marquez95,

In this case, you will need to derive a new class from CRhinoGetPoint and override
OnMouseMove, to calculate the axes, and DynamicDraw to draw them.

Something like this:

cmdSamplePointOnSurface.cpp

– Dale

I am working on Rhino 5 and the override keyword gives me error for the functions with it and the method DrawCurve doesnt exist. Is there any other way to solve this problem?

@f.leon.marquez95, the version of C++ used by Visual Studio 2005 does not recognize the override specifier. So for use, just remove it.

– Dale

Hello, as long as I am using the Rhino 5 and Visual Studio 2010, I cannot use the method DrawCurve in the line code dp.DrawCurve(*m_curves[i]); saying that CRhinoDisplayPipeline does not have the method DrawCurve. Can I use another method? I just want to draw the x and y axis

Hi @f.leon.marquez95,

In Rhino 5, use CRhinoViewport::DrawCurve(const ON_Curve& curve);.

– Dale