Select object by WindowBox

I want the programm select object by a closed curve in xy plane. I do not want get all object and see which in the closed curve. I just want to input the curve and get the object in the curve on plane xy.Am I clear Thank you!
Some thing like _SelBoundary

If you are using Rhino 5, the Rhino 5 C++ SDK, and you want to select a region of objects (like SelBoundary), then use the RhinoRegionSelect() SDK function. See rhinoSdkUtilities.h for more details.

Sorry dale, I use .net. I can’t find this function in net!

I will get together with @stevebaer and see that support for this C++ SDK function is added to RhinoCommon.

Thank you. hope I can use it soon!

I just added two new functions to RhinoCommon. FindByWindowRegion and FindByCrossingWindowRegion functions will be available on the object table (doc.Objects) in SR7.

two maybe not enough. can you give a function that findbypolylineRegion ?

The functions do take polylines as input defining the region, so they should work for you.

OH,yes. dying for that.Can you tell me when will SR7 be released?

We are very close to releasing SR6. Once that is out, we will focus on releasing a SR7 release candidate shortly after.

Hi, Steve. I want use the two function ,but I can’t create a right RhinoViewport. Can you tell me how to create a right RhinoViewport? I just have the ability to get the activeViewport!
I am confused about the RhinoViewport Class!

    Dim mview As Rhino.Display.RhinoViewport = New Rhino.Display.RhinoViewport'Me.RhinoDocument.Views.ActiveView.ActiveViewport
Dim acview As rhino.Display.RhinoViewport = Me.RhinoDocument.Views.ActiveView.ActiveViewport
MVIEW.SETCONSTRUCTIONPLANE(ACVIEW.CONSTRUCTIONPLANE)
MVIEW.SETCAMERADIRECTION(ACVIEW.CAMERADIRECTION, 0)
MVIEW.SETCAMERALOCATION(ACVIEW.CAMERALOCATION, 0)
MVIEW.SETCAMERATARGET(ACVIEW.CAMERATARGET, 0)
MVIEW.SETCLIPPINGPLANES(ME.RHINODOCUMENT.VIEWS.ACTIVEVIEW.ACTIVEVIEWPORT.GETFRUSTUMBOUNDINGBOX)
Dim Mcurobjts As rhinoobject() =Me.RhinoDocument.Objects.FindByWindowRegion(MVIEW, x, True, objecttype.Curve)
Dim mcurvelist As New list(Of curve)
For Each rhinobj As rhinoobject In mcurobjts
  mcurvelist.add(rhinobj.Geometry)
Next
a = mcurvelist

I GEt nothing

If you need to set a viewport to a “right” view, then you can do something like this:

Dim view As Rhino.Display.RhinoView = doc.Views.ActiveView
If (view IsNot Nothing) Then
    view.ActiveViewport.SetProjection(Rhino.Display.DefinedViewportProjection.Right, "Right", True)
    view.Redraw()
End If

Does this help?

yes, then another question.
I want store the orginal view, and restore the view after my code perform.
I don’t how to do that.
thank you.

Something like this should work:

Rhino.Display.RhinoView view = doc.Views.ActiveView;
if (null == view)
  return Result.Failure;

view.ActiveViewport.PushViewProjection();

// TODO: modify view here...

view.ActiveViewport.PopViewProjection();
view.Redraw();

Thank you ,I will try it

What’ the code mean, PushviewProjection and popviewprojection?

Rhino maintains a view “stack” so you can undo/redo view changes using the UndoView/RedoView commands.

I feel confused about the class about views.
I handle many view operates,Undoview may take too much time

Your tips seems usless.I paste code here,hope someone can give me a better solution!

 Protected Overrides Sub SolveInstance(ByVal DA As Kernel.IGH_DataAccess)
            If TypeFilter = "\\" Then
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "必须在菜单中选择一个类型(Must select a type in menu)")
                Return
            End If
            Dim Selectplane As New GH_Structure(Of GH_Plane)
            Dim pts As New GH_Structure(Of GH_Point)
            If Not DA.GetDataTree(0, Selectplane) Then Return
            If Not DA.GetDataTree(1, pts) Then Return
            Dim Tcount As Integer = 0
            If Selectplane.Branches.Count <> pts.Branches.Count Then
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "plane的树枝数不等于points的树枝数(Plane's branch count not equal Points' branch count)")
                Return
            Else
                Tcount = Selectplane.Branches.Count
            End If

            Dim Mview As Rhino.Display.RhinoViewport = RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport
            '  RhinoDoc.ActiveDoc.Views.RedrawEnabled = False
            Dim Rtree As New GH_Structure(Of IGH_Goo)
            Dim originmess As String = Message
            Dim Morginview As Rhino.Display.RhinoView = RhinoDoc.ActiveDoc.Views.ActiveView
            If Morginview Is Nothing Then Return
            Morginview.ActiveViewport.PushViewProjection()
            Try
                ' Dim Selplane As Plane = RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.ConstructionPlane

                For Ibranch As Integer = 0 To Tcount - 1
                    Application.DoEvents()
                    Message = "T:" & Ibranch & ",P:" & (Ibranch / (Tcount - 1)).ToString("0.0%")
                    Dim ppts As New List(Of Point3d)
                    For Each Derghpt As GH_Point In pts.Branch(Ibranch)
                        Application.DoEvents()
                        ppts.Add(Derghpt.Value)
                    Next
                    Dim ghplane As GH_Plane = Selectplane.Branches(Ibranch).First
                    Dim splane As Plane = ghplane.Value
                    'If Vector3d.CrossProduct(splane.ZAxis, Selplane.ZAxis).Length > 0.1 Then
                    Mview.SetToPlanView(splane.Origin, splane.XAxis, splane.YAxis, False)
                    '   End If

                    Dim arrtype As String() = {"point", "curve", "brep", "mesh", "Annotation", "dot"}
                    Dim arrtypeindex As Integer() = {DocObjects.ObjectType.Point, _
                                                     DocObjects.ObjectType.Curve, _
                                                     DocObjects.ObjectType.Brep, _
                                                     DocObjects.ObjectType.Mesh, _
                                                     DocObjects.ObjectType.Annotation, _
                                                     DocObjects.ObjectType.TextDot}
                    Dim arrbrepindex As Integer() = {DocObjects.ObjectType.Brep, DocObjects.ObjectType.Surface, _
                                                     DocObjects.ObjectType.Extrusion}

                    Dim doc As RhinoDoc = RhinoDoc.ActiveDoc
                    Dim docobj As ObjectTable = doc.Objects
                    Dim rt As New List(Of IGH_Goo)
                    Dim Mfilter As New ObjectEnumeratorSettings
                    If Regex.IsMatch("brep", TypeFilter) Then
                        For Each Intindex As Integer In arrbrepindex
                            Application.DoEvents()
                            Dim docobjlist As New List(Of RhinoObject)
                            If Order = 1 Then
                                For Each alldocobj As RhinoObject In docobj.FindByCrossingWindowRegion(Mview, ppts, True, Intindex)
                                    Application.DoEvents()
                                    docobjlist.Add(alldocobj)
                                Next
                            Else
                                For Each alldocobj As RhinoObject In docobj.FindByWindowRegion(Mview, ppts, True, Intindex)
                                    Application.DoEvents()
                                    docobjlist.Add(alldocobj)
                                Next
                            End If

                            rt.AddRange(docobjlist.Select(Function(geoobj As RhinoObject) GH_Convert.ObjRefToGeometry(New ObjRef(geoobj.Id))))
                        Next
                    End If
                    For i As Integer = 0 To arrtype.Count - 1
                        Application.DoEvents()
                        If i = 2 Then Continue For
                        If Regex.IsMatch(arrtype(i), TypeFilter) Then
                            Dim docobjlist As New List(Of RhinoObject)
                            If Order = 1 Then
                                For Each alldocobj As RhinoObject In docobj.FindByCrossingWindowRegion(Mview, ppts, True, arrtypeindex(i))
                                    Application.DoEvents()
                                    docobjlist.Add(alldocobj)

                                Next
                            Else
                                For Each alldocobj As RhinoObject In docobj.FindByWindowRegion(Mview, ppts, True, arrtypeindex(i))
                                    Application.DoEvents()
                                    docobjlist.Add(alldocobj)
                                Next
                            End If

                            If arrtypeindex(i) = 512 Or arrtypeindex(i) = 8192 Then
                                rt.AddRange(docobjlist.Select(Function(geoobj As RhinoObject) GH_Convert.ToVariant(geoobj)))
                            Else
                                rt.AddRange(docobjlist.Select(Function(geoobj As RhinoObject) GH_Convert.ObjRefToGeometry(New ObjRef(geoobj.Id))))
                            End If
                        End If
                    Next
                    Rtree.AppendRange(rt, Selectplane.Path(Ibranch))

                Next
                Message = originmess
                Morginview.ActiveViewport.PopViewProjection()
                Morginview.Redraw()
                ' Mview.ParentView.Redraw()
                ' RhinoDoc.ActiveDoc.Views.RedrawEnabled = True
                '  Mview.PreviousViewProjection()
            Catch ex As Exception
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, ex.Message & Environment.NewLine & ex.StackTrace)
                Message = originmess
                Return
            End Try
            DA.SetDataTree(0, Rtree)
        End Sub

Sorry my tips are useless to you. Maybe you should provide more information. You never mentioned you were writing a Grasshopper component. What is the component supposed to do? What problem are you trying to solve? Perhaps if you provide more information and detail, you might get a tip that is not useless…