Sketchup freeze when escape a sketchup tool

Hi all,
I’m developing a tool that insert and rotate component only one specific point.
On pc, on Sketchup 2016, when I start the tool and press CRTL+N or CRTL+O or file/new or file/open Sketchup stop to asnwer. Everything is lock. When I’m clicking the ‘ding’ of the alert message is ringing but I can escape only by pressing escape.
The problem is not coming when i’m selecting another tool.
Is it a knowed problem ?
I can’t share all my script but just some part of it?

Please help.
Best regards

On PC, the common file dialogs are modal. (It means the user can only use the dialog while it is displayed.)

The file dialog has the input focus. Clicking outside the dialog causes the “ding” sound.

… or by clicking the dialog’s “Cancel” button.

It is not a problem. It is normal Windows OS behavior.

why are you even doing that?

do you want to open a new file within your tool?


Thanks for your answer.

I forget to say that after file open the file dialogbox isn’t display.
On other tool, if you select file/open the tool is desactiveted and the dialogbox is open. (like on the move tool).
Previously, I have got the same problem but when launching a wbedialog or a UI I don’t remerber. ( the message box isn’t show and everything is lock with a ‘ding’.
@john_drivenupthewall: I don’t try to open a file dialog with my tool. It’s just a case of use.

does the tool have any of the escape methods?

    def onCancel(_flag, view)

very good idea. I have this

def onCancel(flag,view)

to have _flag don’t change anythings

nside the cancel method, I had a :slight_smile:

puts “yes”.

and console doesn’t show “yes” when i’m clicking on CRTL+N.

Well, the modal dialogbox don’t call the onCancel method in my tool.

When tools are suspended, the SketchUp engine calls the suspend() callback method.
When SketchUp is done doing it’s interruption tasks, it will will re-activate the tool, and call it’s resume() callback method.

Any good tool should always define the 4 basic control callback methods:
activate(), deactivate(), resume() and suspend().

1 Like

Okay, … I now realise what is going on.

Each SketchUp::Model instance has it’s own toolstack of Tool instance objects. When you load a new or different model, the current tool instance must be deactivated. In many cases this tool instance object may even get garbage collected, if it is no longer referenced by the toolstack. (Since the old toolstack itself was destroyed when the old model was unloaded.)

So you will see your tool’s deactivate() callback getting called, just prior to the current model getting unloaded, and the new model being loaded (from disk or a template.)

After the new model is ready, the default tool will be activated. And that tool is the SelectTool.

I did the testing with this:

  class SomeTool

    @@debug = true unless defined?(@@debug)
    def activate(*args)
      called( __method__, method(__method__).parameters() ) if @@debug
    def deactivate(view)
      called( __method__, method(__method__).parameters() ) if @@debug

    def resume(view)
      called( __method__, method(__method__).parameters() ) if @@debug
    def suspend(view)
      called( __method__, method(__method__).parameters() ) if @@debug

    def called( methname, args )
      if @@debug
        puts "#{Module.nesting[0].name}.#{methname}() called."
        args.each_with_index do |arg,i|
          puts "  arg #{i+1} is: #{arg.inspect}"
    end ###

  end # tool class

Correct, I use mytool

and its works perfectly !

Thanks a lot DanRathbun

ps: So we should use select_tool only for Sketchup tool ?

oupss I answer to quick I still have the same problem , let me inspect

No. I have always used Sketchup::Model#select_tool to activate a Ruby UI tool instance.

(The API documentation is misleading. It means Ruby Tool class instance. Not a native SketchUp tool.)

I have never used the push or pop methods of the Sketchup::Tools collection class. They were at one time fragile and caused bugsplats.

There is no (nice) way to inspect the items in the stack. The API writers have not mixed in the Enumerable module, and the collection does not even have a size() method.

1 Like

Thanks DanRathbun !

To be clear, this is kind if Sketchup bug ?

Not a bug. It is features that are not yet implemented in the API.

1 Like