sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Apply Material to ALL Entities on a Layer.

    Scheduled Pinned Locked Moved Plugins
    17 Posts 8 Posters 5.2k Views 8 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      rossthompson
      last edited by

      Hi,

      I am working with some imported geometry (from Revit via DWG file).

      The windows of the building are components on a layer called 'Window'.

      Inside the components are the frame part on a layer 'Frame' and the glass on a layer 'Glass'.

      After importing all the geometry is assigned the default material so it is opaque.

      I simply want to select all entities on the 'Glass' layer regardless of if they are in an active component or otherwise and assign to them a transparent glass material.

      This would mean you can see through the glass into the room.

      A workaround would be to view the model in color by layer mode but I don't want to go down this route.

      Does anybody know of any code that can help?

      Thanks

      Ross

      1 Reply Last reply Reply Quote 0
      • mitcorbM Offline
        mitcorb
        last edited by

        Look at thomthom Material Tools, or Material Replacer in the PluginStore. This is just a guess, but it may be what you need.

        I take the slow, deliberate approach in my aimless wandering.

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          Try this one-liner - set the initial variables to suit the LAYERNAME and an existing MATERIALNAME: copy+paste it into the Ruby-Console +<enter>

          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.entities.each{|e|e.material=ma if e.layer==la};m.definitions.each{|d|next if d.image?;d.entities.each{|e|e.material=ma if e.layer==la}};m.commit_operation;
          

          It's one step undo-able...

          TIG

          1 Reply Last reply Reply Quote 0
          • PixeroP Offline
            Pixero
            last edited by

            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?

            1 Reply Last reply Reply Quote 0
            • TIGT Offline
              TIG Moderator
              last edited by

              @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...

              TIG

              1 Reply Last reply Reply Quote 0
              • PixeroP Offline
                Pixero
                last edited by

                Again, thanks.
                I must try this to see if it works the way I hope.

                1 Reply Last reply Reply Quote 0
                • mitcorbM Offline
                  mitcorb
                  last edited by

                  @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?)

                  I take the slow, deliberate approach in my aimless wandering.

                  1 Reply Last reply Reply Quote 0
                  • F Offline
                    faust07
                    last edited by

                    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

                    1 Reply Last reply Reply Quote 0
                    • A Offline
                      atcad108
                      last edited by

                      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,

                      1 Reply Last reply Reply Quote 0
                      • TIGT Offline
                        TIG Moderator
                        last edited by

                        @atcad108

                        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...

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • A Offline
                          atcad108
                          last edited by

                          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!

                          1 Reply Last reply Reply Quote 0
                          • sdmitchS Offline
                            sdmitch
                            last edited by

                            @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.

                            Nothing is worthless, it can always be used as a bad example.

                            http://sdmitch.blogspot.com/

                            1 Reply Last reply Reply Quote 0
                            • A Offline
                              atcad108
                              last edited by

                              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!

                              1 Reply Last reply Reply Quote 0
                              • TIGT Offline
                                TIG Moderator
                                last edited by

                                By now you should have enough cred to do PMs...

                                TIG

                                1 Reply Last reply Reply Quote 0
                                • sdmitchS Offline
                                  sdmitch
                                  last edited by

                                  @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.

                                  Nothing is worthless, it can always be used as a bad example.

                                  http://sdmitch.blogspot.com/

                                  1 Reply Last reply Reply Quote 0
                                  • A Offline
                                    austinryan
                                    last edited by

                                    Just a dumb couple of questions

                                    1. when running the script it does not paint the reverse faces. can this be done?
                                    2. is there a way to make a toolbar using this script for multiple layers and materials?

                                    Thanks in advance

                                    1 Reply Last reply Reply Quote 0
                                    • TIGT Offline
                                      TIG Moderator
                                      last edited by

                                      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...

                                      TIG

                                      1 Reply Last reply Reply Quote 0
                                      • 1 / 1
                                      • First post
                                        Last post
                                      Buy SketchPlus
                                      Buy SUbD
                                      Buy WrapR
                                      Buy eBook
                                      Buy Modelur
                                      Buy Vertex Tools
                                      Buy SketchCuisine
                                      Buy FormFonts

                                      Advertisement