I am trying to create a palette of materials that conforms to a specific paint manufacturer’s palette. I have been able to extract the colour names and their RGB values from the manufacturer’s website. As there are over 200 colours, I would prefer not to create them manually. Is there a (relatively) straightforward procedure for doing so? Can I format the information in a certain way and put it in a certain place and so have SU recognise it? How difficult would it be to script it?
First you need to write a text file, let’s name it materials.csv
I’ll assume it’s Comma-Separated-Variables [also readable/writable in Excel etc]
Provide the format consistently thus: Name,R,G,B,A
then it’s easily read line by line and parsed into the Name, Red, Green, Blue [0 to 255] and Alpha [1.0 to 0] values.
If the Alpha is not important you can skip it.
Let’s assume an example of: My Lovely Red,255,0,0,1
First set: model=Sketchup.active_model mats=model.materials
lines.each{|line|
line.chomp! # remove \n at the end
next if line.empty?
next unless line =~ /[0-9]/ # no rgb
next if line =~ /^[#]/ # is commented out with a leading #
n,r,g,b,a = line.split(',')
mat=mats.add(n)
mat.color=Sketchup::Color.new(r.to_i, g.to_i, b.to_i)
mat.alpha= a.to_f if a
}
You should now have a material named ‘My Lovely Red’ that is colored red and is fully opaque.
If you process a long list ensure the model is empty and purged before starting.
Then, when its made the new materials, export the model’s materials as a new collection - you’ll get a SKM file in its folder for each material described in your CSV file…
In old times a .skm file could contain a whole bunch of colours in a simple plain text list. I found in my archives a RAL chart that someone once posted to the original atlast forum, but apparently sketchup will no longer recognize it.
Sketchup would actually parse the text .skm file and create a folder of .skm files from it when starting. Version 8 was the last to do it, I think. I imagine it added too much time to sketchup’s load time.
Many thanks for the helpful answers and historic insights. I’ll be giving it a try once i actually manage to extract all the values I need - I thought I had but it’s not as straight forward as it first appeared.
DaveR - help or GTFO. “Did you try a search?” contributes nothing - assume the poster did and either contribute or move on without comment. That kind of reply is … churlish.