Create layers by materials
-
Hi there!
I am trying to figure out if there is a plugin that can do the following (or if it is technically possible to do this at all):
Automatically create layers (by material library definitions, layer name=material name) and put every face on the corresponding layer (if face material=wood, create layer with name "wood" and put face on this layer).
Thank you for your help!
Zsotti -
It's relatively straightforward...
BUT cross-mixing faces onto various layers can be a recipe for disaster and confusion, because layers only control visibility and leave geometry connected across layers even if some things are not visible - therefore deleting an edge on a visible layer might have erased a face that needed the edge that was unseen at that time, and is not found to have vanished until much later... It's much safer to model raw geometry on Layer0 and put it inside groups or components, and then use layers to control visibility of these 'containers'...
IF you have to do it... try this...### Copy/paste code into a file called ### 'TIG-faces2materiallayers.rb' in the Plugins folder module TIG def self model=Sketchup.active_model ents=model.active_entities ents.each{|e| next unless e.class==Sketchup;;Face name="-NIL" name=mat.display_name if mat=e.material e.layer=model.layers.add(name) } end end ### Usage; TIG.faces2materiallayers
EDIT: added the .rb version following requestsTIG-faces2materiallayers.rb
-
Hi zsotti
What you need is exactly what my plugin "layers_materials" does: check it here:
http://rld.crai.archi.fr/rubylibrarydepot/ go to the materials section and search for layers-materials.rb
Regards, -
Thanks Didier!
I thought it existed already... but I couldn't find it, so I wrote one of my own -
much more cleverly coded than mine btw...
-
Dear TIG and Didier !
Thank you very much for your quick reply and of course solution.
I have copied the script of TIG and I am going to try it as soon as possible. I will give you feedback for sure. Maybe funny for you, but it could be one of my most important plugins. I will share with you why, later on.
Thanks!
PS. Dear Didier, I was not able to browse your site. Is it my fault or is it offline sometimes?
-
@unknownuser said:
PS. Dear Didier, I was not able to browse your site. Is it my fault or is it offline sometimes?
http://forums.sketchucation.com/viewtopic.php?p=360023#p360023
-
The site was down yesterday after the PC is was on burned out
I'm actually restoring the saved database copy of it... -
Hi !
What I have promised, my feedback:
1 / TIG's script - surely my fault (I am a rookie in ruby scripting), copied the RB in plugins folder with the right file name, but I have not found the 'command' in any menu. I have tried to write a menu definition according other RB scripts but I did not succeed, sorry.
2 / Didier's script - after his server came back to life I was shocked about how many scripts he has written. Congratulations! I have downloaded the right one and it does (in two steps) exactly what I need.
Thank you for your support!
Zsotti -
My script does not have a menu entry.
It's usage as described is
TIG.faces2materiallayers
in the Ruby Console -
Hi there,
is there a chance to make this script work for sketchup 2018?
The Tig version doesnt work
and the Didier makes the layers but doesnt put the faces in the layers.
kind regards
Richard
-
Edit the ancient RB file [in a plain-text editor, like Notepad++ or BBedit] and change the line:
def self
to read:
def self.faces2materiallayers
It should then work...
Then in the Ruby Console, to run it, you use:
TIG.faces2materiallayers
-
Thanks for the quick reply TIG
I have tried your adjustment and then i get this error code:
TIG.faces2materiallayers
Error: #<NameError: undefined local variable or methodmat' for TIG:Module> C:/Users/richard/AppData/Roaming/SketchUp/SketchUp 2018/SketchUp/Plugins/TIG-faces2materiallayers.rb:11:in
block in faces2materiallayers'
C:/Users/richard/AppData/Roaming/SketchUp/SketchUp 2018/SketchUp/Plugins/TIG-faces2materiallayers.rb:8:ineach' C:/Users/richard/AppData/Roaming/SketchUp/SketchUp 2018/SketchUp/Plugins/TIG-faces2materiallayers.rb:8:in
faces2materiallayers'
<main>:in<main>' SketchUp:1:in
eval'
do you have any suggestions?
kind regards
Richard
-
This is a very very ancient RB...
Try this alternative...### Copy/paste code into a file called ### 'TIG-faces2materiallayers.rb' in the Plugins folder module TIG def self.faces2materiallayers() model=Sketchup.active_model model.active_entities.grep(Sketchup;;Face).each{|face| next unless mat=face.material name=mat.display_name face.layer=model.layers.add(name) } end end ### Usage; TIG.faces2materiallayers
I think it'll work...
However, assigning layers to geometry, like faces and edges, is usually a very bad idea !!!!
They should almost always be given Layer0. -
Dear TIG, after entering TIG.faces2materiallayers in ruby scriptbox I only get []. Any help?
-
For the avoidance of doubt, you must paste the whole of the code into the Ruby Console.
Then to run it useTIG.faces2materiallayers
For it to work there must be faces in the current active entities context, and they must have materials assigned to their fronts.
Faces within groups/components are NOT considered, unless you first edit the container to change the active entities context...If those conditions are met, then any faces should be reassigned to a Layer named after their [front] material, which is made if it does not exist.
To reiterate my earlier comments, moving raw geometry to a layer other than Layer0 is generally not a good idea...
But if you want to do it then this way should work... -
Hi TIG,
I'm dying to try the script. Question though: since Sketchup introduced tags as a replacement for layers, how would the script change? Looking forward to your reply, Gus
-
It doesn't change much at all - under the hood the API still calls them 'layers'.
Very similar to the way it still sees 'scenes' as 'pages' - changed because Layout arrived...
Advertisement