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) = "box"

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

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

Then later on in another model:

model = Sketchup.active_model
definitions = model.definitions

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