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

    Mass rename components

    Scheduled Pinned Locked Moved Developers' Forum
    23 Posts 6 Posters 10.2k Views 6 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

      It works great, but there is a problem. If I make a cabinet component with all the banding info for the parts set and then stretch with FredoScale to get new dimensions the components get renamed

      drawer_left;0W-1L#1
      
      • they become new components. Since i'm using the names as a way to export banding info into the CutList Plus using ";" as a delimiter i have to rename again. But if i put this info as a prefix then everything will be fine and no need to rename again. Can You please make this script do the same but as a prefix? Sorry, if i sound too insolent 😳
      1 Reply Last reply Reply Quote 0
      • D Offline
        dedmin
        last edited by

        true
        banding "0W-1L;"
        Processed 2 Component Definitions
        0W-1L;drawer_right
        0W-1L;drawer_left
        
        true
        
                   :+1:  :+1:  :+1:  :+1:
        
        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          Here's an update:banding.rb

          Usage:

          banding "prefix-" [or banding "prefix-","" or banding "prefix-",nil] adds a prefix

          banding "","-suffix" [or banding nil,"-suffix"] adds a suffix

          banding "prefix-","-suffix" adds a suffix and a prefix

          TIG

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

            Is there a plugin that would export list of component names, definitions and perhaps other details to .csv file
            And the more tricky part - to import back the new filenames after you are done with editing?

            Or a plugin that would list all components with details in an editable spreadsheet within SU?

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              What "other details" ?

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • J Offline
                jeynay
                last edited by

                Hi,

                Is there a way to remove certain words from multiple components at the same time?

                for example I have 50 components that their name has "3D - johnsmith_google_com level 1" at the end of the name. like:

                "10016001_S_DLGBldg1_Central_detached_rvt-1-3D - 3D - johnsmith_google_com level 1"
                "4_ Light Fixture - 4_ Light Fixture-1847101- 3D - johnsmith_google_com level 1"
                "Aluminum Sill Extension - Aluminum Sill Extension-2131210-3D - johnsmith_google_com level 1"

                Is there a script that can remove a certain prefix or suffix? or just removing the first/last 15 or 10 characters in the name would also work.

                This issue is very annoying since the models imported from revit to sektchup end up having more than 100 characters. πŸ˜•

                Thanks

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

                  @jeynay said:

                  Hi,

                  Is there a way to remove certain words from multiple components at the same time?

                  for example I have 50 components that their name has "3D - johnsmith_google_com level 1" at the end of the name. like:

                  "10016001_S_DLGBldg1_Central_detached_rvt-1-3D - 3D - johnsmith_google_com level 1"
                  "4_ Light Fixture - 4_ Light Fixture-1847101- 3D - johnsmith_google_com level 1"
                  "Aluminum Sill Extension - Aluminum Sill Extension-2131210-3D - johnsmith_google_com level 1"

                  Is there a script that can remove a certain prefix or suffix? or just removing the first/last 15 or 10 characters in the name would also work.

                  This issue is very annoying since the models imported from revit to sektchup end up having more than 100 characters. πŸ˜•

                  Thanks
                  You can batch rename components.
                  I assume you mean component-definitions, rather than component-instances which can have individual names based on a shared definition...
                  Here's a simple one-liner to do it...
                  Edit the initial togo="..."; to suit your needs...

                  togo=" - 3D - johnsmith_google_com level 1";m=Sketchup.active_model;m.start_operation('rename defns',true);c=0;m.definitions.each{|d|(d.name=d.name.gsub(/#{togo}/,'');c+=1) if d.name=~/#{togo}/};puts"#{c} definitions renamed.";m.commit_operation;
                  

                  Paste it into the Ruby Console + <enter>, it's one step undoable...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    jeynay
                    last edited by

                    Thanks for the quick reply TIG.I'm assuming this would rename that portion of component's name as well? for exampe if i have 50 instances like
                    "4_ Light Fixture - 4_ Light Fixture-1847101- 3D - johnsmith_google_com level 1-01"
                    "4_ Light Fixture - 4_ Light Fixture-1847101- 3D - johnsmith_google_com level 1-02" so on so forth, would i be able to remove the" 3D - johnsmith_google_com level" portion of those instance names?

                    Thanks in advance

                    @tig said:

                    @jeynay said:

                    Hi,

                    Is there a way to remove certain words from multiple components at the same time?

                    for example I have 50 components that their name has "3D - johnsmith_google_com level 1" at the end of the name. like:

                    "10016001_S_DLGBldg1_Central_detached_rvt-1-3D - 3D - johnsmith_google_com level 1"
                    "4_ Light Fixture - 4_ Light Fixture-1847101- 3D - johnsmith_google_com level 1"
                    "Aluminum Sill Extension - Aluminum Sill Extension-2131210-3D - johnsmith_google_com level 1"

                    Is there a script that can remove a certain prefix or suffix? or just removing the first/last 15 or 10 characters in the name would also work.

                    This issue is very annoying since the models imported from revit to sektchup end up having more than 100 characters. πŸ˜•

                    Thanks
                    You can batch rename components.
                    I assume you mean component-definitions, rather than component-instances which can have individual names based on a shared definition...
                    Here's a simple one-liner to do it...
                    Edit the initial togo="..."; to suit your needs...

                    togo=" - 3D - johnsmith_google_com level 1";m=Sketchup.active_model;m.start_operation('rename defns',true);c=0;m.definitions.each{|d|(d.name=d.name.gsub(/#{togo}/,'');c+=1) if d.name=~/#{togo}/};puts"#{c} definitions renamed.";m.commit_operation;
                    

                    Paste it into the Ruby Console + <enter>, it's one step undoable...

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

                      The initial part of the code snippet togo=" - 3D - johnsmith_google_com level 1";
                      specifies which string will be deleted in the components' names.
                      I you example:
                      "4_ Light Fixture - 4_ Light Fixture-1847101- 3D - johnsmith_google_com level 1-01" "4_ Light Fixture - 4_ Light Fixture-1847101- 3D - johnsmith_google_com level 1-02"
                      etc
                      become
                      "4_ Light Fixture - 4_ Light Fixture-1847101-01" "4_ Light Fixture - 4_ Light Fixture-1847101-02"
                      etc

                      Just edit that to cover what you want to delete...
                      So to leave the final 'ref' as say "1-01", you simply change the togo to say:
                      togo=" - 3D - johnsmith_google_com level";
                      and the renaming is then:
                      "4_ Light Fixture - 4_ Light Fixture-1847101 1-01" "4_ Light Fixture - 4_ Light Fixture-1847101 1-02"
                      etc

                      You choose what's to be deleted...
                      You can always run the code a second time with a new togo string, e.g.
                      togo="4_ Light Fixture - ";
                      Would strip off the duplicated starting reference, leaving:
                      "4_ Light Fixture-1847101 1-01" "4_ Light Fixture-1847101 1-02"
                      etc

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • J Offline
                        jeynay
                        last edited by

                        @tig said:

                        The initial part of the code snippet togo=" - 3D - johnsmith_google_com level 1";
                        specifies which string will be deleted in the components' names.
                        I you example:
                        "4_ Light Fixture - 4_ Light Fixture-1847101- 3D - johnsmith_google_com level 1-01" "4_ Light Fixture - 4_ Light Fixture-1847101- 3D - johnsmith_google_com level 1-02"
                        etc
                        become
                        "4_ Light Fixture - 4_ Light Fixture-1847101-01" "4_ Light Fixture - 4_ Light Fixture-1847101-02"
                        etc

                        Just edit that to cover what you want to delete...
                        So to leave the final 'ref' as say "1-01", you simply change the togo to say:
                        togo=" - 3D - johnsmith_google_com level";
                        and the renaming is then:
                        "4_ Light Fixture - 4_ Light Fixture-1847101 1-01" "4_ Light Fixture - 4_ Light Fixture-1847101 1-02"
                        etc

                        You choose what's to be deleted...
                        You can always run the code a second time with a new togo string, e.g.
                        togo="4_ Light Fixture - ";
                        Would strip off the duplicated starting reference, leaving:
                        "4_ Light Fixture-1847101 1-01" "4_ Light Fixture-1847101 1-02"
                        etc

                        This worked beautifully!!! thank you much appreciated πŸ˜„

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

                          thanks TIG for those amazing scripts
                          i hope you could add the option for
                          removing the first/last 15 or 10 characters from the name

                          @tig said:

                          @jeynay said:

                          Hi,

                          Is there a way to remove certain words from multiple components at the same time?

                          for example I have 50 components that their name has "3D - johnsmith_google_com level 1" at the end of the name. like:

                          "10016001_S_DLGBldg1_Central_detached_rvt-1-3D - 3D - johnsmith_google_com level 1"
                          "4_ Light Fixture - 4_ Light Fixture-1847101- 3D - johnsmith_google_com level 1"
                          "Aluminum Sill Extension - Aluminum Sill Extension-2131210-3D - johnsmith_google_com level 1"

                          Is there a script that can remove a certain prefix or suffix? or just removing the first/last 15 or 10 characters in the name would also work.

                          This issue is very annoying since the models imported from revit to sektchup end up having more than 100 characters. πŸ˜•

                          Thanks
                          You can batch rename components.
                          I assume you mean component-definitions, rather than component-instances which can have individual names based on a shared definition...
                          Here's a simple one-liner to do it...
                          Edit the initial togo="..."; to suit your needs...

                          togo=" - 3D - johnsmith_google_com level 1";m=Sketchup.active_model;m.start_operation('rename defns',true);c=0;m.definitions.each{|d|(d.name=d.name.gsub(/#{togo}/,'');c+=1) if d.name=~/#{togo}/};puts"#{c} definitions renamed.";m.commit_operation;
                          

                          Paste it into the Ruby Console + <enter>, it's one step undoable...

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

                            You could try editing the code as follows - inside the

                            {}
                            

                            block of

                            ...each{|d|...}
                            

                            substitute...
                            Change the value of

                            i=
                            

                            to how many characters you want to loose...
                            To trim off the end use

                            i=10;n=d.name;1.times{n=n.chop};d.name=n;
                            

                            To trim off the start use

                            i=10;n=d.name;n=n[i..-1];d.name=n;
                            
                            

                            TIG

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

                              @tig said:

                              You could try editing the code as follows - inside the

                              {}
                              

                              block of

                              ...each{|d|...}
                              

                              substitute...

                              Change the value of

                              i=
                              

                              to how many characters you want to loose...

                              To trim off the end use

                              i=10;n=d.name;1.times{n=n.chop};d.name=n;
                              

                              To trim off the start use

                              i=10;n=d.name;n=n[i..-1];d.name=n;
                              > 
                              

                              thanks for your help,much appreciated
                              would you please create a file for me with a calling name like
                              delete "last_3"
                              or
                              Delete"frist_5"
                              i am able to use the banding "prefix-" script
                              i don't know anything about coding
                              but your script is what i was looking for and need

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

                                Copy/Paste this code into the Ruby Console to rename all of the model's definitions, with 3 characters off the end of their names - change i=3 to another value as desired...

                                m=Sketchup.active_model;m.start_operation('chop defns',true);c=0;m.definitions.each{|d|i=3;n=d.name;(1.times{n=n.chop};d.name=n;c+=1)};puts"#{c} definition-names chopped.";m.commit_operation;
                                

                                Or use this code to strip 5 characters off the names' beginnings - again edit i=5 as desired...

                                m=Sketchup.active_model;m.start_operation('trim defns',true);c=0;m.definitions.each{|d|i=5;n=d.name;n=n[i..-1];d.name=n;c+=1)};puts"#{c} definition-names trimmed.";m.commit_operation;
                                

                                TIG

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

                                Advertisement