Make material with coluns of excel

hello, I have a table in excel with several columns and a rgb value.
I was wondering if it is possible to create a script that creates in the model all the colors of the table, taking the name and the RGB code.

Sure.
You can import the excel data into SU. There are several topic here about it:
https://forums.sketchup.com/search?q=excel%20%20%23developers%3Aruby-api

Once you have imported and, for example, assuming you have a hash of RGB names-values like

rgb_hash = 
{
  "55-3-Color1-193a" => [162,162,157],
  "Other_color_name" => [1,2,255]
}

You can do somthing like this:

def create_materials(rgb_hash)
  model = Sketchup.active_model
  materials = model.materials
  rgb_hash.each{|name, value|
    new_material = materials.add(name)
    new_material.color = value
  }
end
create_materials(rgb_hash)
  # If there is already a material with the given name, 
  #  then a new unique name is generated using the given name as a base.

Ref:
https://ruby.sketchup.com/Sketchup/Materials.html
https://ruby.sketchup.com/Sketchup/Material.html
https://ruby.sketchup.com/Sketchup/Color.html

3 Likes