Rhino 4 - Point on mesh


#1

Hi,

I have some customers that still uses Rhino 4, and I now need a plugin for Rhino 4 that projects point on mesh.
Can anyone help me?
Should be the same as this for Rhino 5:

       ObjRef Mesh_ref;
        var rc = RhinoGet.GetOneObject("Select the mesh", false, ObjectType.Mesh, out Mesh_ref);
        if (rc != Result.Success) return rc;
        ObjRef obj_ref = Mesh_ref;
        var mesh = obj_ref.Mesh();

        var gp = new GetPoint();
        gp.SetCommandPrompt("Set first point");
        gp.Get();
        if (gp.CommandResult() != Result.Success)
            return gp.CommandResult();
        var set_point = gp.Point();

        Point3d pt1a = new Point3d(set_point.X, set_point.Y, set_point.Z);

        gp = new GetPoint();
        gp.SetCommandPrompt("Set second point");
        gp.Get();
        if (gp.CommandResult() != Result.Success)
            return gp.CommandResult();
        set_point = gp.Point();

        Point3d pt2a = new Point3d(set_point.X, set_point.Y, set_point.Z);

        gp = new GetPoint();
        gp.SetCommandPrompt("Set third point");
        gp.Get();
        if (gp.CommandResult() != Result.Success)
            return gp.CommandResult();
        set_point = gp.Point();

        Point3d pt3a = new Point3d(set_point.X, set_point.Y, set_point.Z);

        var points = new List<Point3d>();
        points.Add(pt1a);
        points.Add(pt2a);
        points.Add(pt3a);


        int[] indices;

        var prj_points = Intersection.ProjectPointsToMeshesEx(new[] { mesh }, points, new Vector3d(0, 0, 1), 0, out indices);

        foreach (var prj_pt in prj_points) doc.Objects.AddPoint(prj_pt);
        doc.Views.Redraw();

(Dale Fugier) #2

Hi @OveJo,

RhinoCommon wasn’t available in Rhino 4, so the above code isn’t going to work.

That you are doing seems pretty simple - you can probably do this with RhinoScript too.

– Dale


#3

Hi Dale,

It’s a good thing that you now have changed to RhinoCommon - it’s easier to understand. :slight_smile:

But for this plug in I’m stuck with Rhino_DotNET.

And script will not work - this is only a small part of the plugin, so I need these points for other operations.

I’m trying to us the following:

public static bool RhinoProjectPointsToMeshes(RMA.OpenNURBS.IOnMesh[] meshes, RMA.OpenNURBS.IOn3dPointArray points, RMA.OpenNURBS.ValueTypes.Vector3d projectDirection, out RMA.OpenNURBS.On3dPointArray outPoints, out int[] indices, double tolerance)

Could you please help me?

Regards

Ove


(Dale Fugier) #4

I have not tested this. But it should work:

public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
{
  MRhinoGetObject go = new MRhinoGetObject();
  go.SetCommandPrompt("Select mesh");
  go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object);
  go.EnableSubObjectSelect(false);
  go.EnableGroupSelect(true);
  go.GetObjects(1, 0);
  if (go.CommandResult() != IRhinoCommand.result.success)
    return go.CommandResult();

  MRhinoObjRef obj_ref = go.Object(0);
  IOnMesh mesh = obj_ref.Mesh();
  if (null == mesh)
    return IRhinoCommand.result.failure;

  On3dPointArray points = new On3dPointArray();
  MRhinoGetPoint gp = new MRhinoGetPoint();
  for (int i = 0; i < 3; i++)
  {
    switch (i)
    {
      case 2:
        gp.SetCommandPrompt("Set third point");
        break;
      case 1:
        gp.SetCommandPrompt("Set second point");
        break;
      default:
        gp.SetCommandPrompt("Set first point");
        break;
    }

    gp.GetPoint();
    if (gp.CommandResult() != IRhinoCommand.result.success)
      return gp.CommandResult();

    points.Append(gp.Point());
  }

  IOnMesh[] meshes = new IOnMesh[] {mesh};
  Vector3d dir = new Vector3d(0.0, 0.0, 1.0);
  On3dPointArray out_points = new On3dPointArray();
  int[] indices;
  double tol = context.m_doc.AbsoluteTolerance();

  bool rc = RhUtil.RhinoProjectPointsToMeshes(meshes, points, dir, out out_points, out indices, tol);
  if (rc)
  {
    for (int i = 0; i < out_points.Count(); i++)
      context.m_doc.AddPointObject(out_points[i]);
    context.m_doc.Redraw();
  }

  return IRhinoCommand.result.success;
}

– Dale


#5

Thank you very much Dale!