# How to change color of several layers at once

**URL:** <https://forums.sketchup.com/t/how-to-change-color-of-several-layers-at-once/110258>\
**Category:** Ruby API\
**Tags:** materials, layers, colors, opacity\
**Created:** [December 4, 2019, 12:07am UTC](https://forums.sketchup.com/t/how-to-change-color-of-several-layers-at-once/110258 "2019-12-04T00:07:49Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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:** [December 4, 2019, 1:21am UTC](https://forums.sketchup.com/t/how-to-change-color-of-several-layers-at-once/110258/5 "2019-12-04T01:21:02Z")

</div>

Well … try this. You can adjust the Gray RGB components to suit.

[Example\_SetAllLayersGray.rb](https://forums.sketchup.com/uploads/short-url/qIxMtQ9fqudSUM7RvWt3BWSh6DX.rb) (878 Bytes)

```ruby
module Example
  module SetAllLayersGray

    extend self

    @@loaded = false unless defined?(@@loaded)

    def gray_all_layers
      shade = Sketchup::Color.new(77,77,77)
      layers = Sketchup.active_model.layers.to_a
      choice = UI.messagebox('Set "Layer0" black?',MB_YESNO)
      if choice == IDYES
        zero = layers.delete(Sketchup.active_model.layers["Layer0"])
        zero.color= "Black" if !zero.nil?
      end
      layers.each do |layer|
        layer.color= shade
      end
    end

    def gray_all_layers_command
      choice = UI.messagebox('Set all layer colors to gray?',MB_YESNO)
      gray_all_layers() if choice == IDYES
    end

    unless @@loaded
      UI.menu('Plugins').add_item('Set All Layers Gray') {
        gray_all_layers_command()
      }
      @@loaded = true
    end

  end
end

```

---

_[View the full topic](https://forums.sketchup.com/t/how-to-change-color-of-several-layers-at-once/110258)._
