Current tool unavailable after invoking new plugin

Hi everyone!

I’m just getting started with the SketchUp Ruby API and decided to create a quick plugin to experiment with a couple of things.

I followed the official Github examples and currently have 2 files in the Plugins folder: the plugin registration file (which is pretty much boilerplate) along with another file that lives in a subdirectory. The content of the latter is as follows:

require 'sketchup.rb'

module CMExtension
  module Tool

    class Reconstruction
      def activate
        puts "Hi there!"

    def self.activate_tool
    unless file_loaded?(__FILE__)
      menu ='Plugins')
      menu.add_item('Reconstruction') {

  end # module Tool
end # module CMExtension

This gives me a new button under the “Extensions” menu, however, after I click the said button any tool that was previously selected from the toolbar (like “Select” or “Dimension Tool”) doesn’t respond to click events unless I select a different tool. The Hi there message shows up in the Ruby console as expected.

I believe that my Reconstruction class is missing a handler of some sort that would bring the focus back to whatever was selected previously. Any ideas on how to achieve that?

Thanks in advance!

NO other tool will get mouse clicks or keystrokes whilst your tool is active. This is the nature of the “active tool”. Ie, all other tools are inactive.

The same is true for your tool. It will never receive mouse clicks or keystrokes whilst any other tool is active.

Your test tool here does not do anything that would signal to the user that it is active, like displaying it’s own cursor, setting it’s own status text, setting the bounds for it’s drawing, etc.

Tools do not do this and should not normally be coded to have this behavior.

A tool remains active until the user selects another tool. Tools should have states begining with the initial state 0. After the user completes a tool’s main task, the tool should return (be reset) to state 0. If in later states the user clicks the ESC key the convention is that either the last state is undone, or the tool is completely reset.

So if you are thinking that the tool would do something, then exit back to the previous tool, I would argue that probably a tool is not what is needed. A command object that executes a method and returns (without affecting the active tool) may be what is needed instead.

1 Like

Thanks a lot for the clarification, Dan! Indeed, I was looking for a command object instead.