sketchucation logo sketchucation
    • Login
    โ„น๏ธ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Global Layer Name Change

    Scheduled Pinned Locked Moved Developers' Forum
    13 Posts 3 Posters 447 Views 3 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

      ### This changes all matching layer names
      ### You simply change the values of txt1="" and txt2="" to suit...
      txt1="Aqua";txt2="Jason";Sketchup.active_model.layers.each{|layer|layer.name=layer.name.gsub(txt1,txt2)}
      ### paste the line of text "txt1=...txt2)}" into the Ruby console
      ### and then <enter> to make the changes...
      
      

      This replaces [gsub] any 'Aqua - ' text with 'Jason - ' - thus all of the prefixes are changed and other layers are left alone... You are most unlikely to have the txt1 inside the rest of a layer's name so that is safe...

      You Len and Left is 'basic' - ruby has other tools... if anything you are making things more complicated !

      IF you wanted ALL layers to have the 'Jason' prefix then I recommend doing it in two steps - a bit like you suggest...
      Step 1: ...txt1="Aqua - "; txt2=""... ###that will remove all of the prefixes.
      Step 2: ...prefix="Jason - "...layer.name=prefix+layer.name... ###that will add the prefix to all layers...

      TIG

      1 Reply Last reply Reply Quote 0
      • Bob JamesB Offline
        Bob James
        last edited by

        Thanks again, TIG.
        I wasn't trying to make it more complicated: I used to program in Basic, Fortran IV and Algol (guess that dates me ๐Ÿ˜Ž ๐Ÿ˜ฎ) and, more recently, making macros in Excel and Access. It was the only way I knew how to try to communicate what I needed.

        Again, thank you.

        One, hopefully last, dumb guy question: do I make what you gave me into a ruby (Rename_layers.rb) and then type the other into the ruby console?

        i7-4930K 3.4Ghz, 2x GTX780 6GB, 32GB DDR3-1600 ECC, OCZ Vertex 4 500GB, WD Black 3TB, 32TB NAS, 4x 27" Monitors, SpaceMouse Pro, X-keys XK-60

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

          If you make a ruby script you'll need to make a definition and give it two arguments txt1 and txt2 etc... Easier is the the single line that can be copy/pasted into the Ruby Console + <enter> [with the txt1=/txt2= adjusted as desired]...

          txt1="Aqua";txt2="Jason";Sketchup.active_model.layers.each{|layer|layer.name=layer.name.gsub(txt1,txt2)}
          

          copy all of this line of code...

          TIG

          1 Reply Last reply Reply Quote 0
          • Bob JamesB Offline
            Bob James
            last edited by

            Gave it a try. This is what I got:

            txt1="3 Studio";txt2="3 Wood Room";Sketchup.active_model.layers.each{|layer|layer.name=layer.name.gsub(txt1,txt2)}
            #Sketchup::Layers:0x206dd8d0

            I don't know what that second line means, but the layer names were changed
            I'm amazed that that simple command did the trick!

            Thank you Ruby Master TIG ๐Ÿ‘

            i7-4930K 3.4Ghz, 2x GTX780 6GB, 32GB DDR3-1600 ECC, OCZ Vertex 4 500GB, WD Black 3TB, 32TB NAS, 4x 27" Monitors, SpaceMouse Pro, X-keys XK-60

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

              The #Sketchup::Layers:0x206dd8d0 is simply what is returned at the end of processing the model's layers. It's a pointer to the list of them... You could use

              layers=Sketchup.active_model.layers
              

              which sets 'layers' as a variable pointing at the model's layers list, you can then use 'layers' later on - e.g.

              layers.each{|layer|puts layer.name}
              

              which would print out each of the layers' names in turn in the Ruby Console [puts 123] You could then use layers again to do something else - like change some layers' names...

              TIG

              1 Reply Last reply Reply Quote 0
              • Chris FullmerC Offline
                Chris Fullmer
                last edited by

                Bob, you design SpacePorts?!?!??!?!!? ๐Ÿ˜ฎ ?!?!?!??!?!?!

                Thats the coolest thing ever.

                Chris

                Lately you've been tan, suspicious for the winter.
                All my Plugins I've written

                1 Reply Last reply Reply Quote 0
                • Bob JamesB Offline
                  Bob James
                  last edited by

                  This is getting REALLY interesting. My large models normally have over 100 layers. Attached is a partial listing for one model. Note the "0 - Small Payload" names: these were changed with your original name changer command - ENORMOUSLY HANDY.

                  In my original post I said:

                  @bob james said:

                  Or if I've developed a new model and want to re-organize the layers with prefixes.

                  This is true even for older models that are used as a basic model to which different user equipment is added.

                  You said
                  @tig said:

                  you can then use 'layers' later on - e.g.

                  layers.each{|layer|puts layer.name}
                  

                  which would print out each of the layers' names in turn in the Ruby Console [puts 123] You could then use layers again to do something else - like change some layers' names...

                  I see what you said, but don't really know how to implement it.

                  Quite often it would be very handy to be able to re-organize the layer names into a better grouping (since there is no provision for sub-layers under a heading layer). In this case being able to have a list of the layers, change the names and then feed it back in. The "feed-back" would probably have to be in the same order as the original name list, but SU would then re-sort them into the new groupings. Is this kind of thing doable?

                  You can see some of the scenarios I've done at http://www.calspace.com at Processing Scenario - Small and Processing Scenario - Large


                  ![About one-fourth of the layers list. Note the "0 - Small Payload" names: these were changed with your original name changer command - ENORMOUSLY HANDY](/uploads/imported_attachments/XbPH_Picture12.png "About one-fourth of the layers list. Note the "0 - Small Payload" names: these were changed with your original name changer command - ENORMOUSLY HANDY")

                  i7-4930K 3.4Ghz, 2x GTX780 6GB, 32GB DDR3-1600 ECC, OCZ Vertex 4 500GB, WD Black 3TB, 32TB NAS, 4x 27" Monitors, SpaceMouse Pro, X-keys XK-60

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

                    The list is in the order the layers were made. It would be possible to make a sorted list and put that into a text file - it it were any use to you...

                    However, probably the easiest way to rename stuff as you want is to make step by step changes to how the layers are prefixed. You can change prefix1 to another1 and the prefix2 to another2 etc etc. Just do the rename steps a few times till they are as you want... You just need to do a little bit of thinking about how you might want to rename and check that no steps will interfer with a previous one...

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • Bob JamesB Offline
                      Bob James
                      last edited by

                      Chris: Yeh, and SU makes it possible for an old duffer like me to do enormously interesting things ๐Ÿ˜„

                      TIG: I tried your new commands and, as advertised, I received a list of the layer names in the Ruby Console. Interestingly, the order is not the same: I assume they are in the order that they were created (or something like that)?

                      Now what can I do with this with regard to changing names in SU?


                      The top part of the Ruby Console list

                      i7-4930K 3.4Ghz, 2x GTX780 6GB, 32GB DDR3-1600 ECC, OCZ Vertex 4 500GB, WD Black 3TB, 32TB NAS, 4x 27" Monitors, SpaceMouse Pro, X-keys XK-60

                      1 Reply Last reply Reply Quote 0
                      • Bob JamesB Offline
                        Bob James
                        last edited by

                        Good to go.

                        Thanks for taking the time to mess with this small stuff, I certainly appreciate it.

                        i7-4930K 3.4Ghz, 2x GTX780 6GB, 32GB DDR3-1600 ECC, OCZ Vertex 4 500GB, WD Black 3TB, 32TB NAS, 4x 27" Monitors, SpaceMouse Pro, X-keys XK-60

                        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