Let User click on a hole feature on solid model

Hi,

I’m developing a plugin and I want to allow user to click on a hole feature on a closed Brep model. I want to can get the Circular Curve that he clicked and the Normal direction of that hole. So that I can programmatically place a screw in it.

Anyone know if there is a trick to do this with RhinoCommon functionalities.

Better if the user see highlighted border as a visual cue during the picking.

Thanks.

I would probably start with the GetEdgeCurves method if you want the user to pick the edge of the holes.

After you get the curve you should probably make a reference to where to pick the screw. Maybe a point you have added to your screw? Then you can move the screw from that point to the center of the EdgeCrv.

Hi Victor,

To pick a “hole”, you will probably want to create an instance of a GetObject class and set the geometry filter to BrepLoop. Here is an example that may help you:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var go = new GetObject();
  go.SetCommandPrompt("Select holes");
  go.GeometryFilter = ObjectType.BrepLoop;
  go.GeometryAttributeFilter = GeometryAttributeFilter.InnerLoop;
  go.GetMultiple(1, 0);
  if (go.CommandResult() == Result.Success)
  {
    for (var i = 0; i < go.ObjectCount; i++)
    {
      var obj_ref = go.Object(i);
      var ci = obj_ref.GeometryComponentIndex;
      if (ci.ComponentIndexType != ComponentIndexType.BrepLoop)
        return Result.Failure;

      var brep = obj_ref.Brep();
      if (null == brep)
        return Result.Failure;

      var loop = brep.Loops[ci.Index];
      if (null == loop)
        return Result.Failure;

      for (var lti = 0; lti < loop.Trims.Count; lti++)
      {
        var ti = loop.Trims[lti].TrimIndex;
        var trim = brep.Trims[ti];
        if (null != trim )
        {
          var edge = brep.Edges[trim.Edge.EdgeIndex];
          if (null != edge)
          {
            // TODO: do somethign with edge curve.
            // In this case, we'll just add a copy to the document.
            var curve = edge.DuplicateCurve();
            if (null != curve)
              doc.Objects.AddCurve(curve);
          }
        }
      }
    }
  }

  doc.Views.Redraw();
      
  return Result.Success;
}

Thank you Dan, Jordy and Dale,

I’ll try them out and post back!