I found the reference here for the Pick Points from conduit.
https://wiki.mcneel.com/developer/rhinocommonsamples/pickobject
And I built the Code on similar statements:
using System;
using System.Collections;
using System.Collections.Generic;
using Rhino;
using Rhino.Geometry;
using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;
using Rhino.Input.Custom;
using Rhino.Commands;
using Rhino.Display;
using System.Drawing;
using System.Windows.Forms;
/// <summary>
/// This class will be instantiated on demand by the Script component.
/// </summary>
public class Script_Instance : GH_ScriptInstance
{
#region Utility functions
/// <summary>Print a String to the [Out] Parameter of the Script component.</summary>
/// <param name="text">String to print.</param>
private void Print(string text) { /* Implementation hidden. */ }
/// <summary>Print a formatted String to the [Out] Parameter of the Script component.</summary>
/// <param name="format">String format.</param>
/// <param name="args">Formatting parameters.</param>
private void Print(string format, params object[] args) { /* Implementation hidden. */ }
/// <summary>Print useful information about an object instance to the [Out] Parameter of the Script component. </summary>
/// <param name="obj">Object instance to parse.</param>
private void Reflect(object obj) { /* Implementation hidden. */ }
/// <summary>Print the signatures of all the overloads of a specific method to the [Out] Parameter of the Script component. </summary>
/// <param name="obj">Object instance to parse.</param>
private void Reflect(object obj, string method_name) { /* Implementation hidden. */ }
#endregion
#region Members
/// <summary>Gets the current Rhino document.</summary>
private readonly RhinoDoc RhinoDocument;
/// <summary>Gets the Grasshopper document that owns this script.</summary>
private readonly GH_Document GrasshopperDocument;
/// <summary>Gets the Grasshopper script component that owns this script.</summary>
private readonly IGH_Component Component;
/// <summary>
/// Gets the current iteration count. The first call to RunScript() is associated with Iteration==0.
/// Any subsequent call within the same solution will increment the Iteration count.
/// </summary>
private readonly int Iteration;
#endregion
/// <summary>
/// This procedure contains the user code. Input parameters are provided as regular arguments,
/// Output parameters as ref arguments. You don't have to assign output parameters,
/// they will have a default value.
/// </summary>
private void RunScript(List<Point3d> pts, bool on, ref object A)
{
if (on)
{
var pickPoints = PickPoints(pts);
A = pickPoints;
}
else
{
return;
}
}
// <Custom additional code>
//Class defintion for ConduitPoint
public class ConduitPoint
{
public ConduitPoint(Point3d point)
{
Color = System.Drawing.Color.AliceBlue;
Point = point;
}
public System.Drawing.Color Color { get; set; }
public Point3d Point { get; set; }
}
//Class Definition to Getpoints from the Conduit
public class GetConduitPoint: GetPoint
{
private List<ConduitPoint> _conduitPoints;
public GetConduitPoint(List<ConduitPoint> conduitPoints)
{
_conduitPoints = conduitPoints;
}
//Function to access the mouseDown Event
protected override void OnMouseDown(GetPointMouseEventArgs e)
{
base.OnMouseDown(e);
var picker = new PickContext();
picker.View = e.Viewport.ParentView;
picker.PickStyle = PickStyle.PointPick;
var xform = e.Viewport.GetPickTransform(e.WindowPoint);
picker.SetPickTransform(xform);
foreach (var cp in _conduitPoints)
{
double depth;
double distance;
if (picker.PickFrustumTest(cp.Point, out depth, out distance))
cp.Color = System.Drawing.Color.Red;
else
cp.Color = System.Drawing.Color.White;
}
}
}
class PointsConduit : Rhino.Display.DisplayConduit
{
private List<ConduitPoint> _conduitPoints;
public PointsConduit(List<ConduitPoint> conduitPoints)
{
_conduitPoints = conduitPoints;
}
protected override void DrawForeground(Rhino.Display.DrawEventArgs e)
{
if (_conduitPoints != null)
foreach (var cp in _conduitPoints)
e.Display.DrawPoint(cp.Point, PointStyle.X, 5, Color.Green);
}
}
//Function to generate Points to access
private List<Point3d> PickPoints(List<Point3d> cPoints)
{
List<Point3d> pickPoints = new List<Point3d>();
List<ConduitPoint> conduitPoints = new List<ConduitPoint>();
var conduit = new PointsConduit(conduitPoints);
conduit.Enabled = true;
var gcp = new GetConduitPoint(conduitPoints);
gcp.SetCursor(Rhino.UI.CursorStyle.ArrowCopy);
while (true)
{
gcp.SetCommandPrompt("select conduit point. (<ESC> to exit)");
gcp.AcceptNothing(true);
gcp.Get(true);
doc.Views.Redraw();
if (gcp.CommandResult() != Rhino.Commands.Result.Success)
{
pickPoints.Add(gcp.Point());
return pickPoints;
}
}
}
// </Custom additional code>
}
It does not pick the points, rather it just places a point at the position of cursor. I am sure I am missing something in here.
Any Guidance?
Script is also attached here
Test_PickPreviewPoints.gh (11.0 KB)