Changing an object's layer

The “Default Tray” was never intended by Microsoft to be the organized tray that the user uses.
It is only a “parking” tray where all the application’s panels are parked “by default” at installation.

It is expected that each user will modify and create there own trays (plural,) organized the way that they best need them. (Ie, docked, floating, auto-hidden, etc.)

I myself have 4 custom tabbed trays docked on the right, and 2 custom trays (TREE and HELP) auto-hidden into the left margin (so they slide into view when I hover over their margin tab.)

I do not need to “scroll up and down a million times”. In fact, I’ve organized them in such a way that I never need to scroll to access any particular inspector panel.

How many layers do your models use ?

I’ve (in the past) posted code examples of a quick layer pick inputbox that could be assigned a shortcut.
It simply displays the layer names in a dropdown control just like the one on the Entity Info panel.
But I am not sure how it’d work if there were hundreds of layer names.


There is also (already) a native SketchUp “Layers” toolbar that does similar tasks.

Here it shows the currently active layer (checkmark and white background) when nothing is selected.
image

Here it shows the assigned layer of a selected entity (select cursor icon and yellow tooltip background.)
Choosing another layer from the toolbar’s dropdown reassigns the selected entity to that layer choice (same as the layer drop down control in the Entity Info panel.)
image

I myself have this toolbar docked at the top left in my second row of toolbars.
Switch it on via View (menu) > Toolbars… > Toolbars (tab) > Layers (checkbox)

This native toolbar display ~23 items and adds a scrollbar for accessing more.

You can open this toolbar and move it to the center of your modeling space.
Then copy this code to a .rb file, name it "toggle_layers_toolbar.rb" or similar, and save it to your user “Plugins” folder (located in the “Users//AppData/SketchUp/…” folder hierarchy.)

If you do not know how to find your “plugins” folder, then right-click the .rb file in Windows explorer and choose Send to > Compressed (zipped) folder. Then rename the file’s extension from .zip to .rbz, and use the manual installation “Install Extension…” button at the bottom of the Extension Manager (or Extensions dialog if using an older version of SketchUp,) to browse to the rbz archive and install the script.

It will load each time SketchUp does. Then assign a shorcut to toggle this toolbar on/off as needed rather then a right-click. (But I did add a right-click handler.)

LAYERS_TOGGLE ||= UI::Command.new('Layers Toolbar') {
  state = UI.toolbar_visible?('Layers') # get the state
  UI.set_toolbar_visible('Layers', !state)  # toggle it
}.set_validation_proc {
  UI.toolbar_visible?('Layers') ? MF_CHECKED : MF_UNCHECKED
}

UI.menu('View').add_item(LAYERS_TOGGLE)

UI.add_context_menu_handler do |context_menu|
  if !Sketchup.active_model.selection.empty?
    context_menu.add_item(LAYERS_TOGGLE)
  end
end

ADD: If you also wish to have a submenu off the context menu, that lists layers so you can reassign, then use this context menu handler instead. (But, when you get up above 34 layers some will not show because SketchUp’s context menu does not automatically display new columns.)

UI.add_context_menu_handler do |context_menu|
  mdl = Sketchup.active_model
  if !mdl.selection.empty?
    sub = context_menu.add_submenu('Layer reassign',0)
    context_menu.add_separator
    lays = mdl.layers.map(&:name).sort
    lays.each do |name|
      sub.add_item(name) do
        mdl.selection.each {|e|
          next if [Sketchup::Edge,Sketchup::Face,Sketchup::Vertex].include?(e.class)
          e.layer= name 
        }
      end
    end
    context_menu.add_item(LAYERS_TOGGLE,1)
  end
end

Now whenever you hit the shortcut the native Layers toolbar will pop up in the center of your modeling view (or where ever you had positioned it last.) Hit the shortcut again (or the red X button) to hide the toolbar again.

Perhaps Eneroth or someone will add this toolbar toggle to one of their already existing Layering extensions ?

2 Likes