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

    Create layers by materials

    Scheduled Pinned Locked Moved Plugins
    18 Posts 7 Posters 5.0k Views 7 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.
    • TIGT Offline
      TIG Moderator
      last edited by

      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

      TIG

      1 Reply Last reply Reply Quote 0
      • Didier BurD Offline
        Didier Bur
        last edited by

        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,

        DB

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

          Thanks Didier!
          I thought it existed already... but I couldn't find it, so I wrote one of my own πŸ˜’

          TIG

          1 Reply Last reply Reply Quote 0
          • Didier BurD Offline
            Didier Bur
            last edited by

            much more cleverly coded than mine btw... πŸ˜‰

            DB

            1 Reply Last reply Reply Quote 0
            • Z Offline
              zsotti
              last edited by

              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?

              1 Reply Last reply Reply Quote 0
              • massimoM Offline
                massimo Moderator
                last edited by

                @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 πŸ˜‰

                1 Reply Last reply Reply Quote 0
                • Didier BurD Offline
                  Didier Bur
                  last edited by

                  The site was down yesterday after the PC is was on burned out 😞
                  I'm actually restoring the saved database copy of it...

                  DB

                  1 Reply Last reply Reply Quote 0
                  • Z Offline
                    zsotti
                    last edited by

                    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

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

                      My script does not have a menu entry.
                      It's usage as described is
                      TIG.faces2materiallayers
                      in the Ruby Console

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • R Offline
                        rbg
                        last edited by

                        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

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

                          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

                          TIG

                          1 Reply Last reply Reply Quote 0
                          • R Offline
                            rbg
                            last edited by

                            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 method mat' 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:in each' 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

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

                              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.

                              TIG

                              1 Reply Last reply Reply Quote 0
                              • M Offline
                                marcelp102
                                last edited by

                                Dear TIG, after entering TIG.faces2materiallayers in ruby scriptbox I only get []. Any help?

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

                                  For the avoidance of doubt, you must paste the whole of the code into the Ruby Console.
                                  Then to run it use TIG.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...

                                  TIG

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

                                    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

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

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

                                      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