Get point on surface using c++


(F Leon Marquez95) #1

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


(Keyu Gan) #2

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


(Dale Fugier) #3

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


(F Leon Marquez95) #4

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


(Dale Fugier) #5

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


(F Leon Marquez95) #6

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?


(Dale Fugier) #7

@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