Component Definition Name appear "#1"

When I use the following code to place the component according to a certain location and give him a name, I found that when I changed the location, the component name sometimes has a suffix with “#1”, but I don’t want him, please ask me how to cancel。

mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
path=Sketchup.find_support_file "panel.skp","components"
def_list=mod.definitions
test_panel= def_list.load path
test_panel.name= "test_panel"
tran=Geom::Transformation.translation [100,0,0]
inst1=ent.add_instance test_panel,tran

0a1db2fc111032632b809c42ddef9d7 83be0c1c466c773a440170e45ff478e

For example,when I change translation to [200,0,0],I find all of my component definition name changed from “test_panel” to “test_panel#1”

If there’s already a component definition named ‘test_panel’ then when you rename the recently loaded ‘panel’ component SketchUp appends #1, #2 etc - assuming you want to make it unique.
You can circumvent it by first checking definition names for ‘test_panel’ and renaming that temporarily with a ‘random string’.
Then rename the loaded component as ‘test_panel’.
Replace the instances of ‘random string’ with the ‘test_panel’ definition - finally delete the unused ‘random string’ using definition.entities.clear! [within an ‘operation’ block] - or from v2018 definitions.remove(definition) - or perhaps definitions.purge - but that might affect things outside of the scope of your tool !

2 Likes
test_panel = def_list["test_panel"] || def_list.load(path)
test_panel.name= "test_panel" if test_panel.name.empty?