How to select a face in any given component with a single click?

I have a component. in first click i select the component but select any face of component i have to click multiple can i achieve this face in single click using ruby code

You can use the PickHelper class and picked_face method.

However SketchUp is designed to have objects neatly separated and in most cases it is best not to pick entities in other drawing contexts than the active. When viewing a component from the outside, the individual edges and faces inside usually doesn’t matter, but it is what the component represents that do.

but i have to put a coordinate (x,y) here in code

ph = view.pick_helper
ph.do_pick(x, y)
edge = ph.picked_edge

how shall i do it???

study the old test ruby and modify/update to your requirements…

pickhelpertooltests.rb (11.6 KB)


Some plugins use the default selection tool (= the plugin is not yet activated) and then they get the entity from the selection. This does not work here, because you cannot customize the behavior how the selection tool works.

Therefore you need to implement your plugin as a Tool. Only the active tool can get the coordinates of the mouse pointer. In a callback method like onLButtonDown, you get the x, y coordinates as parameter and pass them to the pick helper.

1 Like

Beware that SU expects that selected entities are in the active context. If you select entities outside of the active context you might experience unexpected behaviours.


Perhaps a good note to add to the Sketchup::Selection#add method … or the class introduction ?

1 Like