Mass instance rename help

New to sketch up, but named 10,000 instances manually and need to rename them. Can anyone help with Ruby or a plugin?

The model is a warehouse with individual pallet positions… name examples (section, aisle, bay, elevation) 1.1.1A.1, 1.1.1B.1, 1.1.1A.2, 1.2.1A.1,

I need to take the A and B out and add another .nn at the end of the string. If A then .1 if B then .2 etc.

Thanks for help and suggestions

What version of SketchUp are you using?

Desktop 2023.1

Put that in your forum profile.

I moved this thread to a category where you will probably get to the right folks to help you with a Ruby script.

Thank you DaveR

Have you tried Chatgpt? With the proper prompt it could probably create an script for you to do that I’m not a programmer and I don’t know it is possible or not, I don’t know of a plugin that can do that, the components are still instances or have you made them unique to rename?

I’m so new I’m not sure if they are unique or not. I assume they are not unique: I created the pallet component and copy and pasted and named the instance. I will try ChatGPT, that’s a good idea

I’ll see what anyone else says but I think I can make this work:

Get the current active model in SketchUp

model = Sketchup.active_model

Regular expression to match instance names like 01.01.01A.01 or 01.01.01B.01

name_pattern = /^(\d+.\d+.\d+)([A-Z]).(\d+)$/

Mapping of suffix letters to corresponding numbers

suffix_mapping = Hash[(‘A’…‘Z’)…26)]

Iterate through all the instances in the model

model.entities.each do |entity|
if entity.is_a?(Sketchup::ComponentInstance) && =~ name_pattern
# Extract relevant parts from the current name
prefix = $1
suffix_letter = $2
suffix_number = $3.to_i

# Convert suffix letter to corresponding number
new_suffix_number = suffix_mapping[suffix_letter]

# Create the new instance name format
new_name = "#{prefix}.#{'%02d' % new_suffix_number}.#{'%02d' % suffix_number}"

# Change the instance name to the new format = new_name


1 Like

Copying will create another instance of the same component definition, as will move/copy, move/array copy and the equivalent rotate copy. You should only need a distinct/unique definition when the component has different contents.

You can check whether components are unique in several ways. Select one and look at entity info. At the top of entity info it will tell you how many instances of that definition are present in the model. Alternatively, you can look at the components window and see how many distinct definitions are there. Model info statistics will tell you how many definitions are in the model, but won’t show their names or give a thumbnail view.

Edit: I’m not at my computer so I can’t try it, but in principle it looks like your code snippet should work. Of course, regex’s are notoriously tricky things to get right :thinking:

Consider something like this…

model = Sketchup.active_model
defns = model.definitions
model.start_operation('rename_defns', true)
  name =
  if name =~ /^[1][\.][12][\.][1][A-Z][\.][1]/ # matches a set pattern
    nname = name
    ('A'...'Z').each_with_index{|e, i|
      next unless name =~ /#{e}/ # find a matching letter in name
      p name
      i += 1 # 0 >> 1 etc
      p nname = name+'.'+i.to_s
    p nnname = nname.gsub(/[A-Z]/, '') # remove any A-Z letters = nnname # rename defn
model.commit_operation # so that it's one-step undo-able

Copy/paste into the Ruby Console…
Not foolproof but it might work…

1 Like