• Login
sketchucation logo sketchucation
  • Login
๐Ÿค‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Incremental rename bunch of components

Scheduled Pinned Locked Moved Plugins
9 Posts 5 Posters 754 Views
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 1 Mar 2010, 09:46

    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 1 Mar 2010, 10:17

      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
      • T Offline
        thomthom
        last edited by 1 Mar 2010, 10:25

        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 1 Mar 2010, 10:30

          @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
          • T Online
            TIG Moderator
            last edited by 1 Mar 2010, 18:16

            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 1 Mar 2010, 18:42

              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 1 Mar 2010, 19:05

                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
                • T Online
                  TIG Moderator
                  last edited by 1 Mar 2010, 19:22

                  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 1 Mar 2010, 19:54

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

                    ๐Ÿ˜„

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

                    Advertisement