# Sketchup freeze when escape a sketchup tool

**URL:** <https://forums.sketchup.com/t/sketchup-freeze-when-escape-a-sketchup-tool/23213>\
**Category:** Ruby API\
**Tags:** sketchup, api\
**Created:** [April 6, 2016, 4:21pm UTC](https://forums.sketchup.com/t/sketchup-freeze-when-escape-a-sketchup-tool/23213 "2016-04-06T16:21:03Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![denis\_bolomier](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/denis_bolomier/32/1580_2.png) [@denis\_bolomier](https://forums.sketchup.com/u/denis_bolomier)\
**Post date:** [April 6, 2016, 4:21pm UTC](https://forums.sketchup.com/t/sketchup-freeze-when-escape-a-sketchup-tool/23213/1 "2016-04-06T16:21:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [April 6, 2016, 4:53pm UTC](https://forums.sketchup.com/t/sketchup-freeze-when-escape-a-sketchup-tool/23213/2 "2016-04-06T16:53:34Z")

</div>

> [@denis\_bolomier](#):
>
> 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.

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

> [@denis\_bolomier](#):
>
> When I’m clicking the ‘ding’ of the alert message is ringing …

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

> [@denis\_bolomier](#):
>
> … but I can escape only by pressing escape.

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

> [@denis\_bolomier](#):
>
> Is it a _known_ problem ?

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

---

<div class="post-metadata">

**Author:** ![john\_drivenupthewall](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@john\_drivenupthewall](https://forums.sketchup.com/u/john_drivenupthewall)\
**Post date:** [April 6, 2016, 4:56pm UTC](https://forums.sketchup.com/t/sketchup-freeze-when-escape-a-sketchup-tool/23213/3 "2016-04-06T16:56:26Z")

</div>

> [@denis\_bolomier](#):
>
> when I start the tool and press CRTL+N or CRTL+O or file/new or file/open

why are you even doing that?

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

john

---

<div class="post-metadata">

**Author:** ![denis\_bolomier](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/denis_bolomier/32/1580_2.png) [@denis\_bolomier](https://forums.sketchup.com/u/denis_bolomier)\
**Post date:** [April 6, 2016, 6:02pm UTC](https://forums.sketchup.com/t/sketchup-freeze-when-escape-a-sketchup-tool/23213/4 "2016-04-06T18:02:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![john\_drivenupthewall](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@john\_drivenupthewall](https://forums.sketchup.com/u/john_drivenupthewall)\
**Post date:** [April 6, 2016, 8:46pm UTC](https://forums.sketchup.com/t/sketchup-freeze-when-escape-a-sketchup-tool/23213/5 "2016-04-06T20:46:08Z")

</div>

does the tool have any of the escape methods?

```ruby
    def onCancel(_flag, view)
      reset(view)
    end

```

---

<div class="post-metadata">

**Author:** ![denis\_bolomier](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/denis_bolomier/32/1580_2.png) [@denis\_bolomier](https://forums.sketchup.com/u/denis_bolomier)\
**Post date:** [April 7, 2016, 9:03am UTC](https://forums.sketchup.com/t/sketchup-freeze-when-escape-a-sketchup-tool/23213/6 "2016-04-07T09:03:14Z")

</div>

very good idea. I have this

> def onCancel(flag,view)  
> self.reset(view)  
> end

to have \_flag don’t change anythings

nside the cancel method, I had a 🙂

> 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.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [April 7, 2016, 10:12am UTC](https://forums.sketchup.com/t/sketchup-freeze-when-escape-a-sketchup-tool/23213/7 "2016-04-07T10:12:35Z")

</div>

> [@denis\_bolomier](#):
>
> 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()`**.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [April 7, 2016, 11:42am UTC](https://forums.sketchup.com/t/sketchup-freeze-when-escape-a-sketchup-tool/23213/8 "2016-04-07T11:42:03Z")

</div>

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:

```ruby
  class SomeTool

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

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

    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
        puts
      end
      #
    end ###

  end # tool class

```

---

<div class="post-metadata">

**Author:** ![denis\_bolomier](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/denis_bolomier/32/1580_2.png) [@denis\_bolomier](https://forums.sketchup.com/u/denis_bolomier)\
**Post date:** [April 7, 2016, 12:21pm UTC](https://forums.sketchup.com/t/sketchup-freeze-when-escape-a-sketchup-tool/23213/9 "2016-04-07T12:21:05Z")

</div>

Correct, I use

> @model.tools.push\_tool mytool

and its works perfectly !

Thanks a lot DanRathbun

ps: So we should use select\_tool only for Sketchup tool ?

---

<div class="post-metadata">

**Author:** ![denis\_bolomier](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/denis_bolomier/32/1580_2.png) [@denis\_bolomier](https://forums.sketchup.com/u/denis_bolomier)\
**Post date:** [April 7, 2016, 12:27pm UTC](https://forums.sketchup.com/t/sketchup-freeze-when-escape-a-sketchup-tool/23213/10 "2016-04-07T12:27:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [April 7, 2016, 1:11pm UTC](https://forums.sketchup.com/t/sketchup-freeze-when-escape-a-sketchup-tool/23213/11 "2016-04-07T13:11:03Z")

</div>

> [@denis\_bolomier](#):
>
> ps: So we should use **`select_tool`** only for Sketchup tool ?

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.)

> [@denis\_bolomier](#):
>
> I use `@model.tools.push_tool mytool`

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.

---

<div class="post-metadata">

**Author:** ![denis\_bolomier](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/denis_bolomier/32/1580_2.png) [@denis\_bolomier](https://forums.sketchup.com/u/denis_bolomier)\
**Post date:** [April 12, 2016, 6:33am UTC](https://forums.sketchup.com/t/sketchup-freeze-when-escape-a-sketchup-tool/23213/12 "2016-04-12T06:33:08Z")

</div>

> [@DanRathbun](#):
>
> inspect

Thanks DanRathbun !

To be clear, this is kind if Sketchup bug ?

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [April 12, 2016, 2:16pm UTC](https://forums.sketchup.com/t/sketchup-freeze-when-escape-a-sketchup-tool/23213/13 "2016-04-12T14:16:15Z")

</div>

> [@denis\_bolomier](#):
>
> To be clear, this is kind if Sketchup bug ?

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