Hide tray using api

Hello im working on an extension that tries to overwride the default tools, while in a work mode. This is necessary for using the keyboard to type directly using a bottom ui and for other reasons. Im facing a limitation whit the overwriting of the paint bucket tool, i can overwrite it like other tools, but while it gets selected before being overwritten it automatically opens the tray. I dint find any way to cancel this automatic tray opening by the paint bucket in the api, i know there is a mac option but there is no api option. I cannot cancel a default tool, only overwrite it, and there is no observer that can run before the tools either. Maybe i can get some ideas for this i would really apreciate any help. Thanks

The only control the Ruby API currently gives is to open inspector panels.

There is a remote possibility. Since the user can create ANY named custom tray in which to dock the Materials panel, you could have the user assign a custom shortcut to Toggle Visibility for that tray, …
… then you use a trick to send keystrokes to SketchUp for that menu shortcut.

On the Mac, this requires a 3rd party utility called cliclick.

On Windows, you can use the Windows Scripting Host’s SendKeys method via Ruby’s WIN32OLE class.

For example’s sake, say that the user tells you via an inpubox that the shortcut they’ve chosen is ALT+F8

module Evzyl
  module MyTools

    # Set a default shortcut to toggle the Materials panel tray.
    # This can be changed at anytime after loading extension.
    @matls_shorcut ||= '%{F8}'

    def toggle_materials_panel
      require 'win32ole' unless defined?(WIN32OLE)
      WIN32OLE.new('WScript.Shell').SendKeys(@matls_shorcut)
    end

  end
end

REF: SendKeys method - Windows Script Host


A very advanced pattern might be to read the user’s shortcut setting from the "SharedPreferences.json" file. (This file is located in different places on Mac and Windows.)

1 Like

Thanks a lot for taking ur time and helping whit my issue this means a lot for me, as i really wish to create a quality extension, this issue really felt like a brick wall for me and any kind of help is apreciated! I will try ur method and have a settings section where users can work around and disable this tray by providing a shortcut to sketchup. My actual goal is to prevent SketchUp’s Paint tool from activating (and popping the Materials tray) while our custom tool is active. I’ve already tried:

  • ToolsObserver#onActiveToolChanged to immediately reselect our custom tool when Paint activates.

  • A fast UI.start_timer monitor that detects PAINT_TOOL_ID and calls select_tool(nil), Sketchup.send_action(‘cancelOperation:’) and then reselects our custom tool.

These stop the tool quickly, but the tray still opens as it gets the oportunity to run even for a frame.

If u are willing to help are there any supported way to temporarily block the Paint tool (or default Sketchup tools) while a Ruby tool is active? Or any lower‑level hook that fires before SketchUp switches tools? Or any way to make a tool that uses the keyboard freely without any default Sketchup tool intervention? thanks so much again for your time!

I recently applied your method and was able to find the tray “Toggle Visibility” shortcut in preferences. When I press the Paint tool shortcut (B), the tray still appears for a frame, then disappears using the shortcut hack. So it doesn’t fully solve the keyboard problem in my extension.

Because the tray flashes open, I can’t reliably use the full window for my custom bottom UI. In practice, users would need to keep the side tray open all the time, which isn’t acceptable. That means I likely need to abandon this keyboard approach and try something else.

I do not think so. Supposedly, according to the API docs, the keystroke callbacks will not bubble up if true is returned, but I do not remember this ever preventing shortcuts from changing the tool.

No, I know of none. The ToolsObserver#onActiveToolChanged callback is triggered in the past tense (i.e., after the tool has changed.)

Again, no not at this time. It is a common complaint by tool coders.

Correct. There is no current way to prevent the panel from popping up. It is not just coders, but everyday users are also complaining that there is no way to stop the panel from seizing the keyboard focus. Some users want to use the Paint Sampling feature of the tool and not the Materials inspector, so they’ve asked for a switch the tell SketchUp not to activate the tray panel.

There is nothing else to try, that is exposed to the Ruby API.


FYI, This has no effect on MS Windows. It’s a Mac only action string. See my old example:

[Example] Send Escape Key - Cancel Operation script


Probably not a very good idea. It sounds like you are trying to make SketchUp work like ACAD’s command driven interface. SketchUp was purposefully designed to NOT be like CAD. It has been called “the unCAD”. SketchUp has a tool driven interface where there is always an active tool that the user uses to interact with the geometry.

I would guess that Trimble may take a dim view of an extension that interferes with SketchUp’s default tools. I suggest reading the Terms of Service carefully before releasing anything that does what you describe.

It will always be more acceptable to create your own palette of custom tools rather than circumvent the default tools.

2 Likes

Hey, not sure if you were aware, this exists on Mac. When checked the materials panel opens when the paint tool is activated, when unticked it does not.

No we do not have that option on MS Windows in either 2025 or 2026 versions.

Been on Mac since I started using SketchUp. That said the rest of the materials handling on mac is a train wreck lol.

Thanks a lot for your time and help — and for the warning as well.
I’ll try to build something that I believe SketchUp lacks in the woodworking space, and I’ll worry about the terms later.
I’m looking forward to coming back here and posting about my struggles on this journey.
I’m really grateful for the help and for this forum.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.