[code] Example command to close all active edits

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.2.rb (1.3 KB)

# 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 User
  module CloseAllActiveEdits

    extend self

    VERSION ||= '1.0.2'

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

    def command()

    def edit_active?( model = Sketchup::active_model )
      model.active_path ? true : false

    unless @loaded

      @cmd = UI::Command.new("Close All") {
        Sketchup::active_model.close_active while edit_active?()
      @cmd.set_validation_proc {
        edit_active? ? 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?()

      # Always show command on main Edit menu:

      @loaded = true

    end # unless already loaded

  end # this plugin module
end # toplevel namespace module
1 Like


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?

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.

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.

as Ruby uses a “/” for file separator on both platforms, I wouldn’t consider it a mac bug, but a coding oversight…


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.

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

Thanx Steve!

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

1 Like