Transfer 'color by layer' to 'color by material'
-
Have you seen the plugin that does the subject?
Thanks in advance -
To clarify...
Do you mean, to take each layer's color, and use that color for a [new] material [probably named based on the parent-layer's name?], then apply that material to all entities which are assigned that layer.If so try this... copy+paste+enter in the Ruby Console.
mo=Sketchup.active_model cs={} ns=[] ls=mo.layers p ls[0].name ls.to_a[1..-1].each{|e| #skip Layer0 cs[e.name]=e.color ns<<e.name } mo.start_operation('lcol>>mcol',true) ms=mo.materials ns.each{|k| m=ms.add(k) unless m=ms[k] m.color=cs[k] } mo.entities.each{|e| e.material=ms[e.layer.name] unless e.layer==ls[0] #Layer0 } mo.definitions.each{|d| next if d.image? if d.group? d.entities.each{|e| e.material=ms[e.layer.name] unless e.layer==ls[0] #Layer0 } else #compo d.entities.each{|e| e.material=ms[e.layer.name] unless e.layer==ls[0] #Layer0 } d.instances.each{|e| e.material=ms[e.layer.name] unless e.layer==ls[0] #Layer0 } end } mo.commit_operation putsIt's one step undoable.
It currently skips processing 'Layer0' - but to include it change:
ls.to_a[1..-1].eachto readls.each
and add a new # in front of the 4 lines**#** unless e.layer==ls[0] #Layer0Toggle between Material and Layer view settings to see the effect...
-
Works almost perfect. Please check PM.
Many thanks! -
Transparency [alpha] in colors used 'by layer' is not detectable - I think?
It always returns 255, even when it displays as less !
Neither is a layer's 'texture'.This version also processes 'back-face color'.
mo=Sketchup.active_model cs={} ns=[] ls=mo.layers p ls[0].name ls.to_a[1..-1].each{|e| #skip Layer0 cs[e.name]=e.color ns<<e.name } mo.start_operation('lcol>>mcol',true) ms=mo.materials ns.each{|k| m=ms.add(k) unless m=ms[k] m.color=cs[k] } mo.entities.each{|e| e.material=ms[e.layer.name] unless e.layer==ls[0] #Layer0 e.back_material=ms[e.layer.name] if e.is_a?(Sketchup;;Face) && e.layer!=ls[0] #Layer0 } mo.definitions.each{|d| next if d.image? if d.group? d.entities.each{|e| e.material=ms[e.layer.name] unless e.layer==ls[0] #Layer0 e.back_material=ms[e.layer.name] if e.is_a?(Sketchup;;Face) && e.layer!=ls[0] #Layer0 } else #compo d.entities.each{|e| e.material=ms[e.layer.name] unless e.layer==ls[0] #Layer0 e.back_material=ms[e.layer.name] if e.is_a?(Sketchup;;Face) && e.layer!=ls[0] #Layer0 } d.instances.each{|e| e.material=ms[e.layer.name] unless e.layer==ls[0] #Layer0 } end } mo.commit_operation puts -
Amazing! Many thanks.
P.S. Please publish it it Store so it won't get buried in forum. -
Let's wait a day or two until it gets fine tuned...
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better đź’—
Register LoginAdvertisement