Apply Material to ALL Entities on a Layer.
-
Wow, TIG thanks. Again! Just yesterday I could have used this.
You must be reading my mind...A somewhat related question:
Would it be possible to move groups/components containing geometry with a certain material to a certain layer even if it's nested inside groups/components with other materials? -
@pixero said:
Wow, TIG thanks. Again! Just yesterday I could have used this.
You must be reading my mind...A somewhat related question:
Would it be possible to move groups/components containing geometry with a certain material to a certain layer even if it's nested inside groups/components with other materials?
I assume you mean, to process all definitions and if a definition entities contains one or more pieces of geometry with a material [by name?] then assign a specific layer [by name?] to all of that definition's instances [groups and components]...
Something like this ?ln='LAYERNAME';mn='MATERIALNAME';m=Sketchup.active_model;ma=nil;m.materials.each{|e|ma=e if e.display_name==mn};la=m.layers[ln];m.start_operation('@');m.definitions.each{|d|next if d.image?;d.entities.grep(Sketchup;;Face).each{|e|if e.material==ma;d.instances.each{|i|i.layer=la};break;end}};m.commit_operation;
This looks at Faces for the material...
Note I've added d.image? trap to this code, and I also edited my earlier one-liner... -
Again, thanks.
I must try this to see if it works the way I hope. -
@Pixero:
Would you believe, I went looking at your collection of plugins, thinking that you had developed one for this purpose, when I posted just above.
(I guess those by ThomThom were not the answer?) -
Look at this plugins:
convert_materials_to_layer_names.rb (Al Hart) -
http://sketchucation.com/forums/viewtopic.php?t=36715#p323129
or
layers_materials.rb (Didier Bur) -
http://rhin.crai.archi.fr/rld/plugin_details.php?id=219 -
Hello,
First thanks to all since thanks of your kindness we have all this very usefull pluggins available.
Then for this code I found it very usefull but it doesn't work for me. I am using sketchup 2013 Pro and I paste the code to the ruby console and much the layer and material names but nothing happens. I do like this:ln='LAYER2';mn='MATERIAL2';m=Sketchup.active_model;ma=nil;m.materials.each{|e|ma=e if e.display_name==mn};la=m.layers[ln];m.start_operation('@');m.definitions.each{|d|next if d.image?;d.entities.grep(Sketchup;;Face).each{|e|if e.material==ma;d.instances.each{|i|i.layer=la};break;end}};m.commit_operation;
Please if someone can point out what I am doing wrong I really would appreciate very much.
Thanks, -
Firstly be aware that the code finds all Entities which have the specified Material and assigns them the specified Layer.
The Material's 'name' must already exist in the Model's Materials and be used by some Entities placed in the Model.
The Layer 'name' will be added to the Layers if it does not exist.
So in your example code you show:
ln='LAYER2';mn='MATERIAL2';
Does the Layer with that name, and the Material with that name already exist?
Ensure you use the exact same names... -
Ooohh sorry, I was thinking it goes the other way around. And yes the material and the layer already exist and are exanctly as 'LAYER2' and 'MATERIAL2'.
But what I was trying to do is to apply a material to a layer, the material2 is in the model but not in this layer.
In this case I have a model that it is organitzed by layers and the layers are in different components and groups and subgroups, and I would like to apply a material to a layer and it applies to all the model. Hopefully I explain it well...
I thought this code was for that, sorry. Do you know if it is something like this already? It maybe but I couldn't find it.
Anyway thanks you very much! -
@atcad108 said:
Ooohh sorry, I was thinking it goes the other way around. And yes the material and the layer already exist and are exanctly as 'LAYER2' and 'MATERIAL2'.
But what I was trying to do is to apply a material to a layer, the material2 is in the model but not in this layer.
In this case I have a model that it is organitzed by layers and the layers are in different components and groups and subgroups, and I would like to apply a material to a layer and it applies to all the model. Hopefully I explain it well...
I thought this code was for that, sorry. Do you know if it is something like this already? It maybe but I couldn't find it.
Anyway thanks you very much!I have sent by Private Message a plugin that I think will do what you want.
-
Sorry I replay by here, it says I can't send private messages.
First thank you very much, I think what you send it is exactly what I am looking for but I can't make it work.
How shall I do? I selected the layer and the material in the model and hit the pluggin but nothing come out. I don't know what should be the order or the way to make it work, please if you can tell me...
Thank you very much! -
By now you should have enough cred to do PMs...
-
@atcad108 said:
Sorry I replay by here, it says I can't send private messages.
First thank you very much, I think what you send it is exactly what I am looking for but I can't make it work.
How shall I do? I selected the layer and the material in the model and hit the pluggin but nothing come out. I don't know what should be the order or the way to make it work, please if you can tell me...
Thank you very much!You don't have to do anything just execute the plugin. It should apply MATERIAL0 to LAYER0 and so on. There is no output of any kind. If you pre-select some entities, then it only processes them and ignores the rest of the model.
I guess I sent the plugin to the wrong person since you are not the originator of this thread.
-
Just a dumb couple of questions
- when running the script it does not paint the reverse faces. can this be done?
- is there a way to make a toolbar using this script for multiple layers and materials?
Thanks in advance
-
If you want the same material front & back...
Change where it says ...e.material=ma if e.layer==la
...
To ...(e.material=ma;e.back_material=ma) if e.layer==la
...The toolbar is another kettle of fish...
Advertisement