How to get the selected Point


#1

Hello all,

I want finde the selected point to know if it´s near start or end.

I have this in Python but I want changed to c#

my Python code =>

def select():
    scriptcontext.doc.Objects.UnselectAll()
    getterc = GetObject()
    try:
        getterc.SetCommandPrompt("Please select Purlin on Start or end")
        if getterc.Get() == GetResult.Object: #we wait for the result here
            
            objref = getterc.Object(0)
            id = objref.ObjectId
            
            point = objref.SelectionPoint()
            point = rs.AddPoint(point)
    finally:
        getterc.Dispose() #this will be called in all cases 
    
    scriptcontext.doc.Objects.UnselectAll()
    return id, point

Thanks Robert


#2

Hi Robert,

This should help you:

This is an example to create a line. But it gets 2 points :wink:
Exactly what you are searching for.

Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
gp.SetCommandPrompt("Start of line");
gp.Get();
if (gp.CommandResult() != Rhino.Commands.Result.Success)
return gp.CommandResult();
 
Rhino.Geometry.Point3d pt_start = gp.Point();

//to add a point and get its guid.
Guid pointGuid = doc.objects.addpoint(pt_start)


#3

Thanks jordy,

this I have but I want select a object ( polasurface…) and I want the point I select the obj

to get the info on witch side I have select.

I try but …

this code not worked.

public static Guid SelectPolysurf(String command, RhinoDoc doc)
        {
            doc.Objects.UnselectAll();
            doc.Views.Redraw();

            GetObject go = new GetObject();

            go.SetCommandPrompt(command);
            go.SubObjectSelect = false;
            go.GroupSelect = false;
            go.GeometryFilter = Rhino.DocObjects.ObjectType.PolysrfFilter;
            go.AcceptNothing(true);
            go.GetMultiple(1, 1);
            Point3d point;
            point = go.Point();

            doc.Objects.AddPoint(point);
            if (go.GetMultiple(1, 0) != Rhino.Input.GetResult.Object)
            {
                go.Dispose();
                RhinoApp.WriteLine("no Surf are selected !");
            }

            Rhino.DocObjects.ObjRef[] objref = go.Objects();
            go.Dispose();
            
            doc.Objects.UnselectAll();
            doc.Views.Redraw();

            Guid surf_id = new Guid();
            surf_id = objref[0].ObjectId;
            RhinoApp.WriteLine("point {0} ",point);
            RhinoApp.WriteLine("guid {0} ", surf_id);
            return surf_id;
        }

point -1.23432101234321E+308,-1.23432101234321E+308,-1.23432101234321E+308
guid b24f13e1-9608-4ca4-aff1-498df553dba5

the Guid is ok but the Point everytime the same.


#4

Try this.

It’s in vb.NET but I think you can easily translate it:

  Private Function GetSrf()

            Dim pt0 As Point3d
            Using getPointAction As New GetPoint()
                getPointAction.SetCommandPrompt("Please select point position")
                If getPointAction.[Get]() <> GetResult.Point Then
                    RhinoApp.WriteLine("No point was selected.")
                    Return getPointAction.CommandResult()
                End If
                pt0 = getPointAction.Point()
            End Using

            Dim go As GetObject = New GetObject()
            go.SetCommandPrompt("Select PolySrf")
            go.SubObjectSelect = False
            go.GroupSelect = False
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Brep
            go.AcceptNothing(True)

            If go.Get <> GetResult.Object Then
                Return Result.Failure
            End If

            Dim surf_id As Guid = go.Object(0).ObjectId

            RhinoApp.WriteLine("point {0} ", pt0)
            RhinoApp.WriteLine("guid {0} ", surf_id)

            Return surf_id

        End Function

#5

Hi jordy,

this is double click but I want only on.

but I found out:

public static Guid SelectPolysurf(String command, RhinoDoc doc)
        {
            doc.Objects.UnselectAll();
            doc.Views.Redraw();

            GetObject go = new GetObject();

            Point3d point;
            go.SetCommandPrompt(command);
            go.SubObjectSelect = false;
            go.GroupSelect = false;
            go.GeometryFilter = Rhino.DocObjects.ObjectType.PolysrfFilter;
            go.AcceptNothing(true);
            go.GetMultiple(1, 1);
            
            Rhino.DocObjects.ObjRef oref =   go.Object(0);
            point  = oref.SelectionPoint();

            if (go.GetMultiple(1, 0) != Rhino.Input.GetResult.Object)
            {
                go.Dispose();
                RhinoApp.WriteLine("no Polysurface are selected !");
            }
 
            go.Dispose();
            
            doc.Objects.UnselectAll();
            doc.Views.Redraw();

            Guid surf_id = new Guid();
            surf_id = oref.ObjectId;
            RhinoApp.WriteLine("point {0} ",point);
            RhinoApp.WriteLine("guid {0} ", surf_id);
            return surf_id;
        }

Thanks Robert


(Dale Fugier) #6

Robert,

If you want your code to format correctly on this forum, then do something like this:

```
<paste source code in here>
```

You can even be language specific:

```python
<paste script in here>
```

I’ve gone back and edited your posts so they look better.

– Dale