[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.3.rb (1.4 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 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
1 Like

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?

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.

1 Like

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

john

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

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.

You did not. I DID. (Perhaps you are confused about just what thread you’re posting in ?)

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.

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!

image

Perhaps you can start here…

https://developer.sketchup.com/developers/welcome

As @dezmo shows your forum profile led me astray.

I don’t know what “2 lines of code” you are speaking of, as the file above has 57 lines of code.

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

What post or posts ?

Again, to clarify, in THIS topic thread, I only posted code in the initial opening post 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.