# \[Example\] Command to close all active edits

**URL:** <https://forums.sketchup.com/t/example-command-to-close-all-active-edits/25805>\
**Category:** Ruby API\
**Tags:** closeall, ruby, command, example, code\
**Created:** [May 28, 2016, 11:14pm UTC](https://forums.sketchup.com/t/example-command-to-close-all-active-edits/25805 "2016-05-28T23:14:47Z")\
**Posts on this page:** 15\
**Page:** 1

<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:** [May 28, 2016, 11:14pm UTC](https://forums.sketchup.com/t/example-command-to-close-all-active-edits/25805/1 "2016-05-28T23:14:47Z")

</div>

**An simple example command to close all active editing contexts.**

Once loaded, a keyboard shortcut can be specified in **Preferences** \> **Shortcuts**.  
On PC, we cannot use `CTRL+ESC` (because it’s a system shortcut,) … so I used `CTRL+`` (backtick.)

[CloseAllActiveEdits\_1.0.3.rb](https://forums.sketchup.com/uploads/short-url/peULN2Mq6UvDUeQdQEtVV3LRuNS.rb) (1.4 KB)

```ruby
# encoding: UTF-8
#
# CloseAllActiveEdits.rb
#
# A simple example of creating a contextual UI command to
# close all groups and components that are open for editing.

module Example # <<---<<< This should change to YOUR unique namespace

  module CloseAllActiveEdits

    extend self

    VERSION ||= '1.0.3'

    SAY ||= {
      :tooltip => "Close All Editing Contexts",
      :menutext => "Close All Groups and Components",
      :statusbar => "Close All Group and Component Editing Contexts"
    }

    def command()
      @cmd
    end

    def edit_active?( model )
      model.active_path ? true : false
    end

    unless defined?(@loaded)

      @cmd = UI::Command.new("Close All") {
        model = Sketchup::active_model
        model.close_active while edit_active?(model)
      }
      @cmd.set_validation_proc {
        edit_active?(Sketchup::active_model) ? MF_ENABLED : MF_GRAYED
      }
      @cmd.tooltip= SAY[:tooltip]
      @cmd.menu_text= SAY[:menutext]
      @cmd.status_bar_text= SAY[:statusbar]

      UI.add_context_menu_handler do |menu|
        # Only show command on context menu when in active edit:
        menu.add_item(@cmd) if edit_active?()
      end

      # Always show command on main Edit menu:
      UI.menu("Edit").add_item(@cmd)

      @loaded = true

    end # unless already loaded

  end # this plugin module
end # toplevel namespace module

```

---

<div class="post-metadata">

**Author:** ![StudioAlto](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/studioalto/32/89516_2.png) [@StudioAlto](https://forums.sketchup.com/u/StudioAlto)\
**Post date:** [April 5, 2020, 11:18am UTC](https://forums.sketchup.com/t/example-command-to-close-all-active-edits/25805/2 "2020-04-05T11:18:14Z")

</div>

Hello,

Great script!  
I can’t seem to attribute a keyboard shortcut on Mac (SU 2020).  
When I press down the keyboard shortcut, the screen is flashing but groups don’t close, although it works perfectly with mouse contextual menu.  
Did I miss something?

---

<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 5, 2020, 1:03pm UTC](https://forums.sketchup.com/t/example-command-to-close-all-active-edits/25805/3 "2020-04-05T13:03:52Z")

</div>

> [@StudioAlto](#):
>
> I can’t seem to attribute a keyboard shortcut on Mac (SU 2020).

What keychord did you choose ?

I myself have no Mac so I cannot test or guess the issue is.

I did make a tweak to the script and reposted it above. I seems to work fine in SU2020 on MS Windows platform.

**EDIT** : Steve spotted the problem and I’ve fixed it.

---

<div class="post-metadata">

**Author:** ![slbaumgartner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/32/7302_2.png) [@slbaumgartner](https://forums.sketchup.com/u/slbaumgartner)\
**Post date:** [April 5, 2020, 1:34pm UTC](https://forums.sketchup.com/t/example-command-to-close-all-active-edits/25805/4 "2020-04-05T13:34:25Z")

</div>

The problem is with the / in the name of the command. On Mac it is taken as a path separator in the menu system. That is, “Close All Groups/Components” gets mapped into the menu system as “Edit/Close All Groups/Components”, which leads the shortcut to handle “Components” as if it is a submenu below “Edit/Close All Groups”. Change the / to any other character(s) and all is well (though you have to restart SketchUp to get a new command binding in the menu).

At minimum, this is an undesirable inconsistency between Windows and Mac SketchUp. It could be considered to be a bug in the Mac version.

---

<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 5, 2020, 1:53pm UTC](https://forums.sketchup.com/t/example-command-to-close-all-active-edits/25805/5 "2020-04-05T13:53:30Z")

</div>

as _Ruby_ uses a “/” for _file separator_ on both platforms, I wouldn’t consider it a mac **bug** , but a coding oversight…

john

---

<div class="post-metadata">

**Author:** ![slbaumgartner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/32/7302_2.png) [@slbaumgartner](https://forums.sketchup.com/u/slbaumgartner)\
**Post date:** [April 5, 2020, 2:02pm UTC](https://forums.sketchup.com/t/example-command-to-close-all-active-edits/25805/6 "2020-04-05T14:02:49Z")

</div>

I think it’s a bug because the menu itself doesn’t break it out as a submenu but the shortcut system treats it as if the menu did. Causes the shortcut to make the “bonk” noise for no such command even though the menu works fine.

---

<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 5, 2020, 2:15pm UTC](https://forums.sketchup.com/t/example-command-to-close-all-active-edits/25805/7 "2020-04-05T14:15:21Z")

</div>

> [@slbaumgartner](#):
>
> The problem is with the / in the name of the command. On Mac it is taken as a path separator in the menu system.

Ah. Good and easy fix. Updated the example above and the downloadable file.

**Thanx Steve!**

---

<div class="post-metadata">

**Author:** ![StudioAlto](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/studioalto/32/89516_2.png) [@StudioAlto](https://forums.sketchup.com/u/StudioAlto)\
**Post date:** [April 5, 2020, 2:38pm UTC](https://forums.sketchup.com/t/example-command-to-close-all-active-edits/25805/8 "2020-04-05T14:38:28Z")

</div>

Great! It perfectly works now.  
It definitely speeds up the design process.  
Thank you very much 🙂

---

<div class="post-metadata">

**Author:** ![cakrupp](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/cakrupp/32/48972_2.png) [@cakrupp](https://forums.sketchup.com/u/cakrupp)\
**Post date:** [June 1, 2021, 4:05pm UTC](https://forums.sketchup.com/t/example-command-to-close-all-active-edits/25805/9 "2021-06-01T16:05:02Z")

</div>

Hey Dan et all,  
I’m really glad I started this thread.  
I love your concept of the single key stroke to close all active edits. However, there are times when I want to just move back just a iteration or two so my shortcut is still valid for me.

Secondly, can you tell me how/where the script is loaded.

The other short cut I use is D for Paste in Place after having Cut out a portion of the drawing. Much faster than Edit/ Paste in Place. I use it to move poorly assigned (tags) portions of the model from one group or component to another. Generally, it helps solve the problem of having an edge that is not erasable without losing one of the faces. For moving the adjoining faces to the same group, this works really well.

Further, I use the context menu to make a group or component.  
I use this function a lot.

This solves many issues for me.  
I use SketchUp to design buildings, so in the heat of battle it’s easy to pay too little attention to the proper assignments and I often need to go back and straighten things out.

---

<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:** [June 1, 2021, 7:32pm UTC](https://forums.sketchup.com/t/example-command-to-close-all-active-edits/25805/10 "2021-06-01T19:32:16Z")

</div>

> [@cakrupp](#):
>
> I’m really glad I started this thread.

You did not. [**I DID.**](https://forums.sketchup.com/t/example-command-to-close-all-active-edits/25805) (Perhaps you are confused about just what thread you’re posting in ?)

> [@cakrupp](#):
>
> Secondly, can you tell me how/where the script is loaded.

If you put it in your %AppData% “Plugins” folder, SketchUp will load it upon startup.  
Paste into your File Explorer address bar:  
`%AppData%/SketchUp/SketchUp 2018/SketchUp/Plugins`  
… and hit ENTER.

---

<div class="post-metadata">

**Author:** ![cakrupp](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/cakrupp/32/48972_2.png) [@cakrupp](https://forums.sketchup.com/u/cakrupp)\
**Post date:** [June 2, 2021, 4:20am UTC](https://forums.sketchup.com/t/example-command-to-close-all-active-edits/25805/11 "2021-06-02T04:20:40Z")

</div>

Well then I m glad you started it.  
I assume the line that says SketchUp2018 should be changed to 2020 as that’s my version. Yeah, that’s the ticket; I coded 2020.

Do the 2 different lines of code both have to be loaded or just the last one. Can you tell l know nothing about this coding stuff. When I started learning computer talk it was still on punch cards or tape!

---

<div class="post-metadata">

**Author:** ![dezmo](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/dezmo/32/51058_2.png) [@dezmo](https://forums.sketchup.com/u/dezmo)\
**Post date:** [June 2, 2021, 5:07am UTC](https://forums.sketchup.com/t/example-command-to-close-all-active-edits/25805/12 "2021-06-02T05:07:51Z")

</div>

> [@cakrupp](#):
>
> to 2020 as that’s my version

![image](https://global.discourse-cdn.com/sketchup/original/3X/3/f/3ff459d8998f80895c388fef8d3b1d320330378b.png)

> [@cakrupp](#):
>
> Can you tell l know nothing about this coding stuff.

Perhaps you can start here…

[https://developer.sketchup.com/developers/welcome](https://developer.sketchup.com/developers/welcome)

---

<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:** [June 2, 2021, 3:27pm UTC](https://forums.sketchup.com/t/example-command-to-close-all-active-edits/25805/13 "2021-06-02T15:27:45Z")

</div>

> [@cakrupp](#):
>
> I assume the line that says SketchUp2018 should be changed to 2020 as that’s my version. Yeah, that’s the ticket; I coded 2020.

As @dezmo shows your forum profile led me astray.

> [@cakrupp](#):
>
> Do the 2 different lines of code both have to be loaded or just the last one.

I don’t know what “2 lines of code” you are speaking of, as the file [above](https://forums.sketchup.com/t/example-command-to-close-all-active-edits/25805) has **57** lines of code.

---

<div class="post-metadata">

**Author:** ![cakrupp](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/cakrupp/32/48972_2.png) [@cakrupp](https://forums.sketchup.com/u/cakrupp)\
**Post date:** [June 9, 2021, 5:15pm UTC](https://forums.sketchup.com/t/example-command-to-close-all-active-edits/25805/14 "2021-06-09T17:15:43Z")

</div>

Wasn’t looking at the actual code. Just your post. Seems to be 2 different lines in your posts that need to be loaded  
Looking for clarification.  
Thx

---

<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:** [June 9, 2021, 6:40pm UTC](https://forums.sketchup.com/t/example-command-to-close-all-active-edits/25805/15 "2021-06-09T18:40:22Z")

</div>

> [@cakrupp](#):
>
> Just your post. Seems to be 2 different lines in your posts that need to be loaded  
> Looking for clarification.

What post or posts ?

Again, **to clarify** , in **THIS** topic thread, I only posted code in the [initial opening post](https://forums.sketchup.com/t/example-command-to-close-all-active-edits/25805) which contains 57 lines, **all of which** needed to be loaded.

You need not copy the shown code … that is only for those who do not wish to download the **`rb`** file.  
(FYI, the forum code blocks are limited in their window height, so copying requires you to scroll the code block down to the bottom.)

Instead you can download the whole file and place it in your “Plugins” folder.
