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
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 !