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’).to_a.zip(1…26)]
Iterate through all the instances in the model
model.entities.each do |entity|
if entity.is_a?(Sketchup::ComponentInstance) && entity.name =~ 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
entity.name = new_name
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
model = Sketchup.active_model
defns = model.definitions
model.start_operation('rename_defns', true)
defns.each{|defn|
name = defn.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
defn.name = nnname # rename defn
p defn.name
end#if
}
model.commit_operation # so that it's one-step undo-able
Copy/paste into the Ruby Console…
Not foolproof but it might work…