Component Number Ruby

When you use screen glasses with a name, for example Door #1, Door # 1, Door # 1 …
I need a command in Ruby that stays Port # 1, Port # 2, Port # 3, In short, it can not have any component with the same name in the project.
Is it possible to create a command that solves this, for all levels including component within component?

If you make the component unique the name will also be changed to be unique.

I do not know if that’s what you’re looking for, but maybe I can help you.

I’m not sure what you mean by “screen glasses” - glass screens? glass doors maybe?

You could easily give each instance a unique name, but if you rename the definition this will either apply to all the components of that type or you’d have to make each one unique. If you made them unique then you defeat the purpose of using components in the first place.

If you wanted to rename and number the instance name of every component, my Number Components extension could do that. Get it here for free:
https://extensions.sketchup.com/en/content/number-components

Select all instances from the Components window, choose Number Components from the right-click menu. Then use these settings:
Numbering: Text n
Text Prefix: Door #
Number to: Rename Component
Leave the rest of the settings at default or adjust to what you want.
This will rename the instance name of each component, not the definition name so you will still have multiple copies of that component.

1 Like

Assuming you want to rename definitions and not instances - this code copy+pasted into the Ruby Console + [enter] will ensure that all component definitions in the model, with more than one instance, are made unique. It processes all nested instances’ definitions too…

(m=Sketchup.active_model).start_operation("Uniq'd",true);
c=0;m.definitions.each{|d|next if d.group? || d.image?;next unless d.instances[1];
d.instances[1..-1].each{|i|i.make_unique;c+=1}};
puts"#{c} defs made unique.";m.commit_operation
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.