Change the definition of multiple components in bulk

Is there a method or extension that will change the definitions of multiple components, adding the #1 #2 #3, and so on, all at the same time?
For example:
“Select components” —> “Enter definition (Deck Board)” —> “add number sequence” —> “Deck Board #1, Deck Board #2, Deck Board #3” and so on.

Profile Builder(!:wink:) has a built in ‘batch renamer’ for used Profile members.
There might be more, though…

1 Like

A quick one…
(Edit: You can get as an extenison rbz file form post #9 : Change the definition of multiple components in bulk - #9 by dezmo)

Copy paste the code snippet below to Ruby Console and hit Enter (Return)
If your selection contains at least one componets you will get a context (right click) menu “Rename Definitions”
Click on it and you will get a prompt for Base name.
The definition names will be based on the Base name and will use the first available
“free” integer number “n” at the end of “Base name#n” pattern. (There will be no number at the end if the Base name is unique itself)
You can undo it.
The code was not tested extensively. USE YOUR OWN RISK! No warranties!

Defrename

module Dezmo
module DefsRename
  @@loaded = false unless defined?(@@loaded)

  
  def self.rename_defs
    mod = Sketchup.active_model
    sel = mod.selection
    defins = sel.grep(Sketchup::ComponentInstance).map(&:definition).uniq
    return unless defins.size > 0
    prompts = ["Base name:"]
    defaults = [""]
    input = UI.inputbox(prompts, defaults, "Bulk change component definition names ")
    return unless input
    basename = input.first
    mod.start_operation("Bulk change definitions names", true)
    defins.each{|defin|
      defin.name = mod.definitions.unique_name(basename)
    }
    mod.commit_operation
    "#{defins.size} changes"
  end
  
  unless @@loaded
    UI.add_context_menu_handler do |context_menu|
      if Sketchup.active_model.selection.grep(Sketchup::ComponentInstance).first
        context_menu.add_item("Rename Definitions"){
          rename_defs()
        } 
      end
    end
    @@loaded = true
  end
end
end

(Note: There vas a bug in SketchUp version: 2022.0.315 / 2022.0.316 which prevent to work this snippet properly. Make sure you are using latest update of SU 2022, or earlier versions of SU)

2 Likes

Don’t know how I didn’t know about this… But does it only work with profile members?

@dezmo you’re a boss, rolling that out so quickly. Am I missing something or is it able to create duplicate component names? That would be pretty bad, right?
Thanks friends! I’ll check these out!

Yes. :wink: …to try.

No. All definition names will be unique. (Mind the note at the end of my previous post!!)
There are two instances of some of the same definitions on the example gif above…

Yes.

1 Like

Perhaps you wanted to ask to change the instance nemes of the component definitions, based on the definition name by adding a number sequence at the end of the instance neme? Like this?
numinstname

1 Like

No no, you got it right. I just thought having a component name that was identical to another one, but not the same component was an impossibility. If I manually change the component name, it yells at me if it’s the same as another one.

Yeaaaa… Im on it now! Sorry!


Okay yea, it works like magic!

1 Like

The snippet use the similar “logic” for renaming as a “Make Unique” does if you right click an other instance of same component definition.

If you want I can make - today or tomorrow - a .rbz file, so you can install it as “normal” extension…

1 Like

Dezmo_DefsRename.rbz (1.4 KB)

1 Like

Sweet!!! This will make my slothfulness in naming components a non-issue. Now, I just have to deal with my right click context menu being so long it doesn’t fit on the screen… So many extensions, and a lot of them I never use from the context menu, so they are taking up space for no reason.