The following code does is: When GetPoint() is used, if the Point2d() returned is visually located on some RhinoObject, it returns the ObjRef for those RhinoObject. And then I’m going to try to get these points on the RhinoObject.
Please try the following code :
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
GetPoint getPointAction = new GetPoint();
getPointAction.SetCommandPrompt("Please select the location");
if (getPointAction.Get() == GetResult.Point)
{
//PickContext Setting
System.Drawing.Point pt2d = getPointAction.Point2d();
PickContext pickContext = new PickContext();
pickContext.View = doc.Views.ActiveView;
pickContext.PickStyle = PickStyle.PointPick;
pickContext.PickMode = PickMode.Shaded;
Rhino.Geometry.Line pickLine;
doc.Views.ActiveView.ActiveViewport.GetFrustumLine(pt2d.X, pt2d.Y, out pickLine);
pickContext.PickLine = pickLine;
pickContext.UpdateClippingPlanes();
pickContext.PickGroupsEnabled = true;
//Get the ObjRef[]
ObjRef[] pickList = doc.Objects.PickObjects(pickContext);
foreach( ObjRef objRef in pickList )
{
RhinoApp.WriteLine($"pickList_id: {objRef.ObjectId}");
}
doc.Objects.AddLine(pickLine);
}
return Result.Success;
}
Use this file:
PickContext_Test.3dm (102.1 KB)
If you click the Brep in GetPoint, it will return the wrong ObjRef;
But if you click Extrusion, it will return correctly ObjRef;
And the pickLine is correctly generated.