sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ›£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Incremental rename bunch of components

    Scheduled Pinned Locked Moved Plugins
    9 Posts 5 Posters 818 Views 5 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.
    • D Offline
      dedmin
      last edited by

      Is there a plugin to incremental rename bunch of components:

      @unknownuser said:

      name#N

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

        If it doesnt exist itd be pretty easy to make.

        Just to clarify, is the "name" in "name#N" constant?

        http://remusrendering.wordpress.com/

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          And DefinitionList.unique_name does most of the job:
          http://code.google.com/intl/nb/apis/sketchup/docs/ourdoc/definitionlist.html#unique_name

          @unknownuser said:

          The unique_name is used to generate a unique name for a definition based on a base_name string. For example, a base_name of "Joe" might return "Joe #2"

          Iterate the selected instances, collect the definitions.
          Iterate the definitions naming them by what DefinitionList.unique_name.
          Bob's your uncle.

          Thomas Thomassen β€” SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • D Offline
            dedmin
            last edited by

            @remus said:

            If it doesnt exist itd be pretty easy to make.

            Just to clarify, is the "name" in "name#N" constant?

            Yes. Something like this - cab#1, cab#2 ...

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

              Copy/paste this code into a file called componentrenamer.rb in the Plugins folder.
              To run it you type componentrenamer "NewName#1" in the Ruby Console to change the name of selected component-instances' definitions to NewName#1, NewName#2, NewName#3 etc...
              Note: starting with ' NewName' increments the second one to ' NewName#1'

              
              def componentrenamer(newname)
                model=Sketchup.active_model
                ss=model.selection
                defs=[]
                ss.each{|e|defs << e.definition if e.class==Sketchup;;ComponentInstance}
                defs.uniq.each{|d|d.name=model.definitions.unique_name(newname)}
              end#def
              
              

              πŸ€“

              TIG

              1 Reply Last reply Reply Quote 0
              • D Offline
                dedmin
                last edited by

                Just perfect!!!!

                Clipboard-1.jpg

                Here it is. Thanks TIG!!!

                componentrenamer.rb

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

                  Nice!

                  I'm guessing the # sign is part of the internal SketchUp API? #s cause some problems with how I use models externally. I looked at the (dang simple) code and didn't see any immediate way to suppress the #.

                  This is for keeping all instances the same component, but using a different name, correct? It's not taking all instances and making them unique when renaming? (Similar to what happens when two components of the same name come in but are different -- the second one is named: name#1.)

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

                    To strip the # try adding an extra argument

                    
                    def componentrenamer(newname,nnn=nil)
                      model=Sketchup.active_model
                      ss=model.selection
                      defs=[]
                      ss.each{|e|defs << e.definition if e.class==Sketchup;;ComponentInstance}
                      defs.uniq.each{|d|
                        unn=model.definitions.unique_name(newname)
                        unn=unn.tr("#",nnn)if nnn
                        d.name=unn
                      }
                    end#def
                    
                    

                    The second string in the translation tr nnn can be anything you want - e.g. "-" or "_" ?
                    The usage now has an optional second argument to replace the # with something else
                    e.g. componentrenamer("NewName","_")
                    If you don't add it then the # remains unchanged...
                    πŸ€“

                    TIG

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

                      Thanks TIG! I'll try it out (and learn a little more about SU Ruby)

                      πŸ˜„

                      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