Error: #<TypeError: wrong argument type (expected Sketchup::ComponentDefinition)>

The first thing is please learn to post code correctly in the forum …

Please edit your previous post and repost the code.


  1. Do not use global variables even if you see other naughty code doing it.

Your error message tells you that the 1st argument to entities.add_instance needs to be a Sketchup::ComponentDefinition object.

So it wasn’t. What was it ? You would need to interrogate the model reference in the console …

puts model.class

The first part of you code is not correct… you will want to add the group to the definition’s entities, not the model’s entities:

model = Sketchup.active_model
definitions = model.definitions

definition = definitions.add("box")
entities = definition.entities

group = entities.add_group
gents = group.entitie
cpt = gents.add_cpoint(ORIGIN)
group.name = "box"

#
# add edges and faces, etc. to the group "gents" here
#

# Save the definition to storage:
file_path = "C:/Users/hk/Desktop/box.skp"
definition.save_as(file_path)

Then later on in another model:

model = Sketchup.active_model
definitions = model.definitions

file_path = "C:/Users/hk/Desktop/box.skp"
definitions.load(file_path)
# Place it:
model.entities.add_instance(definition, ORIGIN)
1 Like