Custom Select Tool That Displays Tag Name

It is indeed a good learning experience!

I have a small script that turns various tags on and off (actioned by keyboard shortcuts) including one that toggles between the existing tag and new tag. The script pops up a timed HTMLDialog to say which tag is on - existing or new.

I could look more into HtmlDialog - what I have at the moment is rather clunky and I wasn’t able to figure out how to not have the title bar…


I wondered if I could remove the title bar with HTML or CSS…?

And often I’m toggling fast between existing and new to review what I’m doing and while the HtmlDialog is displayed (briefly) I can’t toggle.

I only need this for when I’m in select mode just perusing and mulling over the model as the select cursor hovers over groups and components.

So if I were to use HtmlDialog I’d want the dialog to be displayed at the cursor briefly (essentially emulating the tooltip) and be something like this…

No, they only control the document inside the window.

You can use the new Sketchup::focus method to give the main window the focus after the dialog is displayed and it’s document has been fully rendered.

In the dialogs’ JavaScript …

      function ready_handler() {
          if (document.readyState === 'complete') {
              sketchup.ready() ;
              // Detach listener:
              document.removeEventListener('readystatechange', ready_handler) ;

      document.addEventListener('readystatechange', ready_handler) ;

And then your Ruby dialog object needs a callback named “ready” …

    @dlg.add_action_callback("ready") { |dialog, params|
      Sketchup::focus if Sketchup.respond_to?(:focus)

There is also an old dummy dialog “hack” that only works on Windows.
(You open a tiny temp dialog and close it with a timer, and the main application gets the focus.)
How to set Focus to Mainwindow - #14 by Renderiza

There is also a WIN32OLE command. See …
How to set Focus to Mainwindow - #6 by DanRathbun

There is no generic MouseObserver implemented that would enable seeing whats under the cursor during native tools (and then using a PickHelper to read object info.)

Perhaps a SelectionObserver subclass, but then that would require that the objects actually be clicked and added to the selection before the layer (or other info) could be read and then displayed by the plugin.

Where did you get stuck? Did you get error messages?

I was able to get on following Dan’s post.

It was a case of my relative inexperience with the SketchUp API.

I do find that the SketchUp API help pages aren’t that helpful for me and that asking on the forum helps with my understanding of the API.

I also tried to recreate the native selection tool, you can see my code here:

I also used model.active_path = to open a group/component
And maybe @click_times in onLButtonDoubleClick will be different between macOS and Win.

1 Like