How to do a crossing box select by ruby?
-
I want to make a script that do crossing box select just like what select tool in Sketchup do ,but I can't find a good method to do it.
I did it by PickHelper firstly,but it only can pick from a point,while now I need pick from a retangle ,how can I do that?
any idea?thanx in advance
-
-
Thereafter your troubles will only increase... then you need to find everything inside that 'box' [or perhaps intersecting the box] depending on whether or not the picking is left-right or right-left - just like the Select tool... Why not get the user to 'preselect' the required objects and then run your code on that selection ?
-
Hmmm, I seem to be missing something.
How do you use the 2d screen coordinates to draw the rubber-band box? It looks like the View#draw2d method takes Point3d objects rather then screen coordinates. Are the docs wrong?
Edit - The docs aren't wrong, I just didn't read them through.
@unknownuser said:The second parameter is an Array of Point3d objects (or several individual Point3d objects). These Point3d objects are in screen space, not 3D space. The X value corresponds to the number of pixels from the left edge of the drawing area. The Y value corresponds to the number of pixels down from the top of the drawing area. The Z value is not used.
So you can use an Array: [x, y] for the 2nd parameter, which should work.
-
@tig said:
Thereafter your troubles will only increase... then you need to find everything inside that 'box' [or perhaps intersecting the box] depending on whether or not the picking is left-right or right-left - just like the Select tool... Why not get the user to 'preselect' the required objects and then run your code on that selection ?
In fact I did preselect object!
I am making a trim tool which use a number of groups trimmed by another number of groups
So I need select a number of groups first then select my tool ,and then select another number of groups, put return key to do the trim at last.
that need select groups while my tool is still active. and I want the select operation just like what the select tool do. -
You could perhaps do a simplified version and map the boundingbox of the groups to a cached array, then use
Geom.point_in_polygon_2D
to see if any of the points are within the selectionbox of your custom tool. It will miss the cases where a selectionbox crosses the group's boundingbox but the corner points are outside, but if you start to do intersection on all that you might very well end up with a sluggish tool. Might be good enough?
Advertisement