Model Coordinates from Mouse click

Is there a way to get the model coordinates of a mouse click? I know the tool object has mouse click events, but I think that is screen coordinates. I would like to be able to click on the model and know that that screen pixel = xyz in the model.

I know this would be tough when you do not click on an entity. For example, where on the z plane would you be if you clicked on nothing? But when you click on a face for example, you should know exactly where you are in model space. But I cannot find a way to get that information from SketchUp.

Any help would be greatly appreciated. Thanks!

Tool class has various methods…
Like onButtonDown…
As does InputPoint… PickHelper and View…

What SketchUp edition and version are you using? (Your profile is incorrect.)

Yes, but … your code passes these screen coordinates to an InputPoint object to get 3D coordinates in model space.

For an example, download the Trimble SketchUp Utilities Tools extension.
Look at the Query Tool (the TrackMouseTool class in the Ruby file.)

* Note that there may be some poor coding practice with global variable use in these files.
(But you still should avoid the use of globals, and use proper Ruby 2 space indents. Some of the example files use 3 or 4 space indents.)

Yes it was incorrect. It is now set. 2021. Thanks!

Yes. It looks like InputPoint will do the trick when matched with the button events from the Tool class. That is exactly what I was looking for. Thanks!

Thanks Dan, TIG had suggested the same thing. I just had not gotten a chance to try it InputPoint. But that, along with screen coordinates from the mouse events from the Tool class are exactly what I was looking for. You just have to know where to look. I spend a tone of my day in the API but there is always something new to discover!
Thanks to both of you!

1 Like