How can I specify a selection rectangle by passing points?

Hello Forum,

I’d like to pick a single point on screen, and return all objects crossing a specified rectangle surrounding that point.

More generally, I’m looking for a way to use rhino’s object selection methods, but under script rather than user control as to where the picks are made (via GetObjects() or input.custom methods or similar). Can anyone help with a way of achieving this?

Paul

Don’t know if this helps, but…

VBRhinoscript has a method WindowPick which emulates a window selection - Python rhinoscriptsyntax does not yet have this method. However, you can script rs.command with _SelWindow or _SelCrossing and achieve more or less the same thing; many people don’t realize you can actually enter coordinates with _SelWindow or _SelCrossing. The selection is view dependent, of course, so you need to set the view you want beforehand.

In the following test script, I artificially created two 3dPoints to indicate the corners of the selection window, then I extracted the X,Y,Z coordinates and converted them into strings. You can of course simply write the strings directly without going through all that, I just assumed you might have some already existing 3dPoints you want to use.

I do not know how to get this stuff directly with RhinoCommon, unfortunately…

–Mitch

import rhinoscriptsyntax as rs
import Rhino

def WindowTest():
    pt1=Rhino.Geometry.Point3d(0,0,0)
    pt2=Rhino.Geometry.Point3d(10,10,0)
    
    strP1=str(pt1.X)+","+str(pt1.Y)+","+str(pt1.Z)
    strP2=str(pt2.X)+","+str(pt2.Y)+","+str(pt2.Z)
    rs.CurrentView("Top")
    rs.Command("_SelWindow "+strP1+" "+strP2, False)
WindowTest()

Mitch, many thanks, that will get the job done.
I don’t normally think to use rs.Command, but seems it still has its uses!
Paul

I just added two new functions to RhinoCommon. FindByWindowRegion and FindByCrossingWindowRegion functions will be available on the object table (doc.Objects) in SR7. This should let you write a “SelWindow” type function in python.

1 Like

I tried this and one limitation seems to be the missing cross selection mode.
When is SR7 planned to be released?
Philip

You mean the workaround code I posted above? Did you try using

rs.Command("_SelCrossing "+strP1+" "+strP2, False)

instead of SelWindow? In theory at least it should work…

It does. I should have been able to find this out by myself. Sorry for wasting your time and thanks again.
Maybe good to know: Objects to be selected must be visible in the specified view. So you have to do a zoom extend on relevant objects.

Yes, it’s 100% view dependent - I guess it’s using the viewport screen coordinates - so that’s exactly what you have to do. This is a bit painful if you are needing to do a lot of iterations, as every time you need to do a zoom and then redraw the screen, which can slow things down considerably.

–Mitch

Yes and also zoom extending all objects is not allways a possible solution because then the scale may be to large and the window pick doesnt work correct.

Steve,
Thanks for adding the FindByWindowRegion and FindByCrossingWindowRegion.
Would it be possible to also add an analogue to SelCircular (especially a crossing option)?
Currently I’m using Helvetosaur’s suggestion above adapted to SelCircular. (which actually works fine, just a little inelegant).
Paul