Bug found by Steve Baumgartner (@slbaumgartner) in a more complex extension under development, on which we are both working.
In SU 2022, but not earlier versions (tested in SU 2021 and 2017) Ruby allows the creation of two components with identical names, and no distinguishing suffix (#1, #2 etc). Steve had several bugsplats which he suspects followed on from this.
The following simplified code demonstrates the problem. On 2022 it generates two Components, both with definitions named “MyName” and 1 instance each. On 2021 9and 2017) the second component gets named “MyName#1” as expected.
def my_uniq_defn_name( name )
names = Sketchup.active_model.definitions.map(&:name)
i = 0
base_name = name
while names.include?( name )
i += 1
name = "#{base_name}##{i.to_s}"
end
name
end
u_name = my_uniq_defn_name( "MyName" )
Looks like a good workaround for the original issue.
In our extension, though, if it has the same name, we now think we want it to use the original component, as the name created is effectively a description of the component parameters. If the name is the same, the component has the same geometry.
I haven’t investigated all the aspects, but since the definition name is supposed to be the unique key for a definition there are many possibilities to break things.