Hi,
I’ve got a list of point3D in my model, I would like the user to choose one among them in the model. I’m using vb.net with rhinocommon.
I tried to look at the constraints or snaps of “getpoint” but I don’t get how to do this.
Thanks for your help!
menno
(Menno Deij - van Rijswijk)
November 16, 2016, 3:31pm
2
I think you should use AddConstructionPoints
GetPoint gp = new GetPoint();
gp.AddConstructionPoints(myListOfPoints);
Thanks for helping. I tried to use this but I don’t get how you cast the RhinoObjects as point3D?
For Each Node As Rhino.DocObjects.RhinoObject In doc.Objects.FindByLayer(“Nodes”)
If Node.ObjectType = DocObjects.ObjectType.Point Then
getPointAction.AddConstructionPoint(trycast(Node, point3D)) 'this does not work
End If
Next
dale
(Dale Fugier)
November 16, 2016, 6:40pm
4
Matthieu,
If you want to ‘select’ point objects, use GetObject
.
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
var go = new GetObject();
go.SetCommandPrompt("Select points");
go.GeometryFilter = ObjectType.Point;
go.GetMultiple(1, 0);
if (go.CommandResult() == Result.Success)
{
foreach (var obj_ref in go.Objects())
{
var point_obj = obj_ref.Point();
if (null != point_obj)
RhinoApp.WriteLine("{0}", point_obj.Location.ToString());
}
}
return Result.Success;
}
If you want to ‘pick’ point locations, use GetPoint
.
– Dale
menno
(Menno Deij - van Rijswijk)
November 16, 2016, 6:51pm
5
Some of the geometry in a Rhino document has a “simple” representation (a point, line, circle, arc, ellipse, sphere, etc.) and an object representation, that wraps the simple representation. When you get a reference to a point in the document, you get a Point
object, that has a .Location
property of type Point3d
. So, I think you can do this in your code (replace line 3)
getPointAcion.AddConstructionPoint(Node.Location)
Thank you Dale, thanks to you I understood the difference between GetObject and GetPoint.
So now that I really select a point object (and not a point location), how could I filter the selection to a particular Layer?
dale
(Dale Fugier)
November 16, 2016, 8:06pm
7
Define a custom GetObject class like this:
internal class GetPointObjectFromLayer : GetObject
{
private readonly int m_layer_index;
public GetPointObjectFromLayer(int layerIndex)
{
m_layer_index = layerIndex;
}
public override bool CustomGeometryFilter(RhinoObject rhObject, GeometryBase geometry, ComponentIndex componentIndex)
{
if (null != rhObject && null != geometry)
{
var point_obj = geometry as Rhino.Geometry.Point;
if (null != point_obj && m_layer_index == rhObject.Attributes.LayerIndex)
return true;
}
return false;
}
}
Then use it like this:
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
int layer_index = doc.Layers.FindByFullPath("Default", true);
if (layer_index < 0)
return Result.Nothing;
var go = new GetPointObjectFromLayer(layer_index);
go.SetCommandPrompt("Select points");
go.GetMultiple(1, 0);
if (go.CommandResult() == Result.Success)
{
foreach (var obj_ref in go.Objects())
{
var point_obj = obj_ref.Point();
if (null != point_obj)
RhinoApp.WriteLine("{0}", point_obj.Location.ToString());
}
}
return Result.Success;
}
– Dale
This is awesome! Thank you so much dale!