• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

[req]rename objects with name of the layer

Scheduled Pinned Locked Moved Plugins
16 Posts 3 Posters 6.3k 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.
  • B Offline
    bagatelo
    last edited by 9 Sept 2013, 11:40

    It would be possible to create a plugin that renames all groups and components that are within a layer using the name of the layer itself?
    If some layer is named "door", and the objects have different names, after running the script we have names like this:
    "door - 001"
    "door - 002"
    "door - 003"
    "door - 004"
    "door - 005"
    etc ...
    It would be necessary only for objects that were at the root of the outliner.
    If not, someone could create a script or plugin to do this, please?
    I also need a plugin that transforms all groups in components, only those who are at the root of the outliner ...

    Thank you!

    While the cat's away, the mice will play

    1 Reply Last reply Reply Quote 0
    • R Offline
      renderiza
      last edited by 10 Sept 2013, 05:50

      Here is little update...
      Both Groups and Components are renamed given the layer they are on now.

      model = Sketchup.active_model
      ents = model.active_entities 	
      groups = ents.grep(Sketchup;;Group)
      components = ents.grep(Sketchup;;ComponentInstance)
      
      groups.each do |group|
        group.name = group.layer.name
      end
      
      components.each do |component|
        component.name = component.layer.name
      end
      

      Now the part I have not been able to solve is the number side of things. How to make each layer have their own numbers so that they don't conflict with each other like this;
      Don't want:
      door - 001
      door - 002
      door - 003
      window - 004
      window - 005

      Do want;
      door - 001
      door - 002
      door - 003
      window - 001
      window - 002

      Any ideas how to solve this?

      [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

      1 Reply Last reply Reply Quote 0
      • R Offline
        renderiza
        last edited by 10 Sept 2013, 06:43

        Hi,

        The code bellow adds the layer name to each group that belong to the layer.

        model = Sketchup.active_model
        ents = model.active_entities 	
        groups = ents.grep(Sketchup;;Group)
        
        groups.each do |group|
          group.name = group.layer.name
        end
        

        You mentioned Components as well so will see if I can add that on next example. You also have incrementing numbers to the side so that is another thing to add.

        Note: To test code I recommend using [as] Ruby Code Editor - http://extensions.sketchup.com/en/content/ruby-code-editor but there are other good ones as well.

        Renderiza

        [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

        1 Reply Last reply Reply Quote 0
        • R Offline
          renderiza
          last edited by 10 Sept 2013, 09:33

          The code below solves the issue mentioned above about the numbers...

          model = Sketchup.active_model
          ents = model.active_entities    
          groups = ents.grep(Sketchup;;Group)
          components = ents.grep(Sketchup;;ComponentInstance)
          num = 0
          
          groups.each do |group|
            group.name = nil.to_s
          end
          
          groups.each do |group|
            if group.name == nil.to_s
              num=0
            end
            
            groups.each do |g|
              if group.layer.name == g.layer.name
                if g.name == nil.to_s
                  num+=1
                  g.name = group.layer.name.concat(" - #{num}")
                end
              end
            end
          end
          
          components.each do |component|
            component.name = nil.to_s
          end
          
          components.each do |component|
            if component.name == nil.to_s
              num=0
            end
            
            components.each do |c|
              if component.layer.name == c.layer.name
                if c.name == nil.to_s
                  num+=1
                  c.name = component.layer.name.concat(" - #{num}")
                end
              end
            end
          end
          

          The code uses numbers like this "door - 1" and not like this "door - 001". Do you need it to be like :door - 001" or is it fine like it is?

          [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

          1 Reply Last reply Reply Quote 0
          • B Offline
            bagatelo
            last edited by 10 Sept 2013, 18:35

            Thanks! Thanks! Thanks!
            I like "door - 001"...
            Can you code this to add some option in some menu?
            And I also like to know if we can do it in the whole model or only visible layers....

            Thanks very much!

            While the cat's away, the mice will play

            1 Reply Last reply Reply Quote 0
            • R Offline
              renderiza
              last edited by 11 Sept 2013, 06:49

              Any suggestions for what should be the name of the plugin?
              Below are potential names...

              • Name by Layer
              • Rename by Layer
              • Entities Name by Layer
              • [Re]Name
              • Renamer

              [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

              1 Reply Last reply Reply Quote 0
              • B Offline
                bagatelo
                last edited by 11 Sept 2013, 09:36

                [Re] name
                I think you could create something that rename numerous things, such as materials, components, Layers, etc ...
                "Central [Re] name"
                http://sketchucation.com/forums/viewtopic.php?f=323&t=47234
                http://sketchucation.com/forums/viewtopic.php?f=323&t=53329

                While the cat's away, the mice will play

                1 Reply Last reply Reply Quote 0
                • R Offline
                  renderiza
                  last edited by 11 Sept 2013, 11:19

                  @bagatelo said:

                  [Re] name
                  I think you could create something that rename numerous things, such as materials, components, Layers, etc ...
                  "Central [Re] name"
                  viewtopic.php?f=323&t=47234
                  viewtopic.php?f=323&t=53329

                  Really like that idea and the name "[Re]Name" is very fitting. But since that idea is more ambitious its advised to work our way there little by little.

                  Maybe starting with renaming groups & components by layer for now and making that into an extension by itself with a different name than "[Re]Name".

                  We can name the extension "Rename by Layer". Here is a Logo for the plugin...Any feedback is welcome.

                  http://s17.postimg.org/m6twx3ekv/Logo_Default.png

                  I started working on making the extension with web-dialog and plan to keep you posted on further progress...cheers!

                  [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                  1 Reply Last reply Reply Quote 0
                  • B Offline
                    bagatelo
                    last edited by 11 Sept 2013, 11:49

                    Thanks for the work, friend.
                    Very much appreciated.
                    Your logo was very interesting.

                    You could change the code to rename the definition name?
                    The reason I asked this plugin is because I'm trying to use the plugin "Solid Quantify by TAK2HATA". It's a wonderful plugin, and I need something to easily modify the names of components. Note the attachment files.


                    plugs.zip

                    While the cat's away, the mice will play

                    1 Reply Last reply Reply Quote 0
                    • B Offline
                      bagatelo
                      last edited by 12 Sept 2013, 02:37

                      Look what I have when I try to execute the last code...
                      Cleared the editor
                      Running the code...
                      Done. Ruby says: Run aborted. Error: undefined method ‘bytesize’ for "1":String

                      While the cat's away, the mice will play

                      1 Reply Last reply Reply Quote 0
                      • D Offline
                        dedmin
                        last edited by 12 Sept 2013, 06:36

                        Great plugin! It would be useful to have "append layer name as prefix/suffix" to the component's name.

                        1 Reply Last reply Reply Quote 0
                        • R Offline
                          renderiza
                          last edited by 12 Sept 2013, 06:52

                          @dedmin said:

                          Great plugin! It would be useful to have "append layer name as prefix/suffix" to the component's name.

                          Great idea! I saw this just about when I published the first version to Plugin Store but maybe for next update your suggestion will be added.

                          Here are some links for the plugin;

                          http://sketchucation.com/resources/pluginstore?pln=RND_Renamer_v1.0.0

                          http://sketchucation.com/forums/viewtopic.php?f=323&t=54165

                          Note: Something important that I noticed about definition names is that if you have 2 entities which are component instances they can't have different definition names.

                          For example;
                          Will not be named like below;
                          Layer: Door
                          component instance#1 definition name = Door - 001
                          component instance#2 definition name = Door - 002
                          component instance#3 definition name = Door - 003
                          component instance#4 definition name = Door - 004

                          They will be name like this;
                          component instance#1 definition name = Door - 004
                          component instance#2 definition name = Door - 004
                          component instance#3 definition name = Door - 004
                          component instance#4 definition name = Door - 004

                          Remember that its a rule that they must be the same. The numbers for definition name will only serve to display the total amount.

                          Cheers! 👍

                          [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                          1 Reply Last reply Reply Quote 0
                          • D Offline
                            dedmin
                            last edited by 12 Sept 2013, 06:57

                            👍 👍 👍

                            1 Reply Last reply Reply Quote 0
                            • R Offline
                              renderiza
                              last edited by 12 Sept 2013, 06:59

                              @bagatelo said:

                              Look what I have when I try to execute the last code...
                              Cleared the editor
                              Running the code...
                              Done. Ruby says: Run aborted. Error: undefined method ‘bytesize’ for "1":String

                              This was an error on my part by using bytesize’ method which I will change to 'length' so it will work. Will try to update all the code example above to eliminate that issue.

                              I also published the plugin as an extension on Plugin Store as 'Rename by Layer' here is the link... http://sketchucation.com/resources/pluginstore?pln=RND_Renamer_v1.0.0

                              Also I made another topic here for future updates and stuff... http://sketchucation.com/forums/viewtopic.php?p=490834#p490834

                              Any feedback about the plugin will be great so I know that to fix on next update...Cheers! 👍

                              [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                              1 Reply Last reply Reply Quote 0
                              • R Offline
                                renderiza
                                last edited by 12 Sept 2013, 07:05

                                I will eventually make an extension plugin with web-dialog that offers some options for the user. For now the code bellow displays the numbers like you suggested.

                                model = Sketchup.active_model
                                ents = model.active_entities   
                                groups = ents.grep(Sketchup;;Group)
                                components = ents.grep(Sketchup;;ComponentInstance)
                                num = 0
                                
                                groups.each do |group|
                                  group.name = nil.to_s
                                end
                                
                                groups.each do |group|
                                  if group.name == nil.to_s
                                    num=0
                                  end
                                 
                                  groups.each do |g|
                                    if group.layer.name == g.layer.name
                                      if g.name == nil.to_s
                                        num+=1
                                        bytenum = num.to_s.length
                                        if bytenum  == 1
                                          zeros = "00"
                                        end
                                        if bytenum  == 2
                                          zeros = "0"
                                        end
                                        if bytenum  >= 3
                                          zeros = nil.to_s
                                        end
                                        g.name = group.layer.name.concat(" - #{zeros}#{num}")
                                      end
                                    end
                                  end
                                end
                                
                                components.each do |component|
                                  component.name = nil.to_s
                                end
                                
                                components.each do |component|
                                  if component.name == nil.to_s
                                    num=0
                                  end
                                 
                                  components.each do |c|
                                    if component.layer.name == c.layer.name
                                      if c.name == nil.to_s
                                        num+=1
                                        bytenum = num.to_s.length
                                        if bytenum == 1
                                          zeros = "00"
                                        end
                                        if bytenum == 2
                                          zeros = "0"
                                        end
                                        if bytenum >= 3
                                          zeros = nil.to_s
                                        end
                                        c.name = component.layer.name.concat(" - #{zeros}#{num}")
                                      end
                                    end
                                  end
                                end
                                

                                Will keep you posted on further development...Cheers! 👍

                                @bagatelo said:

                                And I also like to know if we can do it in the whole model or only visible layers....

                                Right now it does it to all layer no matter if they are visible or not. But an option for only renaming visible layers could be done.

                                [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                                1 Reply Last reply Reply Quote 0
                                • R Offline
                                  renderiza
                                  last edited by 12 Sept 2013, 07:07

                                  @bagatelo said:

                                  You could change the code to rename the definition name?

                                  With the code below the definition name is created.

                                  model = Sketchup.active_model
                                  ents = model.active_entities   
                                  groups = ents.grep(Sketchup;;Group)
                                  components = ents.grep(Sketchup;;ComponentInstance)
                                  num = 0
                                  
                                  groups.each do |group|
                                    group.name = nil.to_s
                                  end
                                  
                                  groups.each do |group|
                                    if group.name == nil.to_s
                                      num=0
                                    end
                                   
                                    groups.each do |g|
                                      if group.layer.name == g.layer.name
                                        if g.name == nil.to_s
                                          num+=1
                                          bytenum = num.to_s.length
                                          if bytenum == 1
                                            zeros = "00"
                                          end
                                          if bytenum == 2
                                            zeros = "0"
                                          end
                                          if bytenum >= 3
                                            zeros = nil.to_s
                                          end
                                          g.name = group.layer.name.concat(" - #{zeros}#{num}")
                                        end
                                      end
                                    end
                                  end
                                  
                                  components.each do |component|
                                    component.name = nil.to_s
                                  end
                                  
                                  components.each do |component|
                                    if component.name == nil.to_s
                                      num=0
                                    end
                                   
                                    components.each do |c|
                                      if component.layer.name == c.layer.name
                                        if c.name == nil.to_s
                                          num+=1
                                          bytenum = num.to_s.length
                                          if bytenum == 1
                                            zeros = "00"
                                          end
                                          if bytenum == 2
                                            zeros = "0"
                                          end
                                          if bytenum >= 3
                                            zeros = nil.to_s
                                          end
                                          #c.name = component.layer.name.concat(" - #{zeros}#{num}")
                                          c.definition.name = component.layer.name.concat(" - #{zeros}#{num}")
                                        end
                                      end
                                    end
                                  end
                                  

                                  @bagatelo said:

                                  The reason I asked this plugin is because I'm trying to use the plugin "Solid Quantify by TAK2HATA". It's a wonderful plugin, and I need something to easily modify the names of components. Note the attachment files.

                                  Will check it out indeed.

                                  [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

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

                                  Advertisement