I have implemented this using onSelectionBulkChange but it requires me to actually click on the entity to get the tooltip to display the tag name.
So looking at the script class ToolTests, the following will display for me a tooltip with the tag name (I know that there is an extension that does this).
def onMouseMove(flags, x, y, view)
ph = view.pick_helper(x, y)
entity = ph.best_picked
layer = entity.layer
view.tooltip = layer.name
end
I’ve been trying to build on the above (so far unsuccessfully) so that I can also select in the same way as the native select tool.
Can someone give me some pointers to what I should be looking at…?
I’m able to select and can select using PickHelper - PICK_CROSSING and PICK_INSIDE but I’m trying to work out how to replicate the visual representation of the selection rectangle…
I’ve been looking at linetools and also the rotated rectangle tool.
Am I looking in the right direction or is there something (simpler?) that I’m missing?
So then the PickHelper does not actually draw the pick box.
Your onMouseMove callback is going to feed the temporary 2nd point (@pt2) for drawing the pick box as the user moves the mouse.
So your draw method needs to know what state your tool is in. (0 for initial state, 1 for when the @pt1 is picked and the pick box needs to be drawn.)
After the 2nd pick and the selection has been done the tool likely should reset to the initial state.
The #window_pick method is called after the user picks the 2nd point in your onLButtonUp callback.
(Ie, this callback should be the state changer for your tool instance.)
EDIT: When I talk of points above, I’m meaning 2D x, y coordinates in screen space.
It will be a test of @pt2.x - @pt1.x to determine what window pick mode and stipple to use.
If positive use solid stipple (PICK_INSIDE), if negative dashed stipple (PICK_CROSSING).
I need to modify this previous statement. You can actually call the #window_pick method as often as you like to discern if there has been a valid pick. (Ie, you can call it each time the mouse moves if you need to.)
If you do a window pick with the native tool you’ll see that nothing is added to the selection until after the left mouse button is released. (For whatever this is worth.)
It’s intended to show a bug so it is quite simplified, but attempts to change the line stipple similar to native Select. There is also a comment explaining how lines are drawn. For this example I simply drew the full rectangle as a closed loop, but SU is a bit smarter and draws lines individually from the direction of the starting point to the current mouse position, so the stipple isn’t shifted when the mouse moves (SketchUp is full of those small details ).
So that bug that Christina refers to where PICK_INSIDE selects a component if one of its sub components is fully inside the window, is annoying!
And the other issue that has cropped up is that there is no API ability to open a group for editing.
But I found the Windows hack method…
def open_group
sel = Sketchup.active_model.selection
if sel.length > 1
return
else
if sel.empty?
return
else
first_sel = sel[0]
if first_sel.respond_to?(:definition)
require "win32ole"
shell = WIN32OLE.new('WScript.Shell')
shell.SendKeys('{ENTER}')
end
end
end
end
The above works as a standalone module but if I include it in def onLButtonDoubleClick it doesn’t work.
You should have a platform guard on the require "win32ole" call.
In order to work you must make sure that the SketchUp application window has the focus.
If the console or a web dialog has the focus then sending ENTER will not work.
Just thinking out loud, while it is a great learning experience to re-implement a SketchUp tool, it often isn’t necessary. Maybe you could display the info you are interested in in a HtmlDialog, and have it work independently of whatever tool is active.