Change the color of several layers at once

Hi,
I’m used to working in “color by layer” mode, so I need to change the layer color quite often.
And I would like to be able to change several layers at the same time.
For example: I import a dwg file, I want to turn all the layers grey. Today I have to change one by one. There are sometimes 50 layers…
Is there a plugin for this ?

Thanks in advance !

Benjamin

It’s a tad slow and clunky to use, as its development was apparently abandoned due to a lack of interest, but this plugin did work for me:

I’d love to hear from others if there is a plugin that does it better.

1 Like

Script here which will change all tags to grey
Change the RGB values if you want something else

# Tags to Grey

# Function to set layer color to grey
def set_layer_color_to_grey(layer)
  # Set the layer color to grey (RGB: 128, 128, 128)
  layer.color = Sketchup::Color.new(128, 128, 128)
end

# Iterate through all layers and set their colors to grey
def change_all_layers_to_grey
  model = Sketchup.active_model

  # Check if the model is empty
  return unless model.layers.any?

  # Iterate through all layers
  model.layers.each do |layer|
    set_layer_color_to_grey(layer)
  end

  # Refresh the view to see the changes
  model.active_view.refresh
end

# Run the script
change_all_layers_to_grey

Would it be trivial to modify this to change colors of selected tags only?

No. Using Ruby API (code), you cannot retrieve the Tags selected on UI.
You need either use my clunky UI to select Tags, or write an other code using HtmlDialog to do it better.

However it is possible to check the selected objects (Drawingelements) and use their associated Tags.

1 Like

This is always true!

I would do like:

  model.start_operation('Set Tag color', true)
  model.layers.each do |layer|
    set_layer_color_to_grey(layer)
  end
  model.commit_operation

Yeah, figured if it was that easy you would’ve done it back when you wrote your plugin in the first place. Clunky as the UI may be, it still works and it’s not that hard to Tab > 0 to quickly move through the list, so I’m grateful I found it, comes up all the time. Thanks!

1 Like

Set color for Tags of selection.

Copy-Paste the code below to Ruby Console and hit Enter (Return).

Select the imported geometries.

Type into Ruby console e.g.:
Dezmo::ColorSelectionTags::set_color(128,128,128)

Where the 128, 128, 128 is an integer (0-255) representing the RGB colors.

The Tags assigned to the selected Drawingelements (including nested) will get a color what you give as R G B parameter.

Use at your own risk! Does not really tested by me! You can undo it…

module Dezmo
module ColorSelectionTags
  extend self
  
  def instance?(obj)
    obj.is_a?(Sketchup::Group) || obj.is_a?(Sketchup::ComponentInstance)
  end

  def get_selected_layers(ents, selected_layers = [])
    ents.each{|ent| 
      selected_layers<<ent.layer if !selected_layers.include?(ent.layer)
      return selected_layers if selected_layers.size == @layers_size
      if instance?(ent)
        get_selected_layers(ent.definition.entities, selected_layers)
      end
    }
    selected_layers
  end

  def set_color(r, g, b)
    model = Sketchup.active_model
    seldwge = model.selection.grep(Sketchup::Drawingelement)
    return unless seldwge.first
    layers = model.layers
    @layers_size = layers.size
    selected_layers = get_selected_layers(seldwge)
    
    model.start_operation("Set color for Tags of selection", true)
    selected_layers.each do |layer|
      layer.color = [r,g,b]
    end
    model.commit_operation
  end
  
end
end


when i want to update tag colors, i export the tags, change the RGB settings via notepad++ and re-import. TIGLayersToList and TIGLayerFromList. all manual but reliable. and if tags are uniquely colored to start, then find & replace is simple in the text editor. there are some caveats for this - one is the re-imported tags will not be part of the tag folder you may have had them in.

Hi,

thanks every one for your answers !
I tried Dezmo_layers_color_at_once_beta3.rbz and it seems to be what I need.
However, I’m still surprised it’s not easyer to change color of 10 layers when it’s easy to change line style of 10 layers… But I’m not a developer ! So there si probably a reason !

Have a nice day !

Benjamin