Hy,
TIG plugin ListLayerColors after some modifications, can create new colors in the pallet with layer's colors
require 'sketchup.rb'
###
class CreateLayerColors
def CreateLayerColors ;;get()
model=Sketchup.active_model
entities = model.active_entities
materials=model.materials
layers=model.layers
if model.rendering_options["DisplayColorByLayer"]==false
model.rendering_options["DisplayColorByLayer"]=true
already_on=false
else
already_on=true
end#if
# create temporary entities for exporting layers
vecteur = Geom;;Vector3d.new 0,0,1
centre = Geom;;Point3d.new 0,0,0
group_temp=entities.add_group()
entities = group_temp.entities
x =0
layers.each {|layer|
model.active_layer = layer
centre = [centre[0], centre[1], centre[2] + x]
edges = entities.add_circle centre, vecteur, 0.01
cercle = entities.add_face(edges)
x= x + 0.01
}
model.save "temp"
mpath = Sketchup.find_support_file "temp", "Plugins/"
model.export(mpath +".obj",false)
mtl=mpath+".mtl"
text=IO.readlines(mtl)
0.upto(text.length-1) do |i|
if text[i]=~/^newmtl */
name=text[i].slice(7..-2)### layer name only
rgbR=((text[i+2].slice(3..11).to_f)*255).to_i.to_s### color rgb values
rgbG=((text[i+2].slice(12..20).to_f)*255).to_i.to_s### color rgb values
rgbB=((text[i+2].slice(21..29).to_f)*255).to_i.to_s### color rgb values
couleur_calque = Sketchup;;Color.new(rgbR.to_i, rgbG.to_i, rgbB.to_i)
unless materials[name]
new_matiere = materials.add name
new_matiere.color = couleur_calque
new_matiere = new_matiere.name
else
materials[name].color = couleur_calque
end
end#if
end#upto
File.delete(mpath+".obj")
File.delete(mtl)
File.delete(mpath)
group_temp.erase!
###
model.rendering_options["DisplayColorByLayer"]=false if already_on==false
###
end#def
end#class
### menu
# add menu items
if(not file_loaded?("CreateLayerColors.rb"))
UI.menu("Plugins").add_item("Create Layer Colors"){CreateLayerColors;;get}
end#if
file_loaded("CreateLayerColors.rb")
###
CreateColorLayer
Christophe