How do I add an instance using Ruby? I can add faces to a group with group.entities.add_face. Then I can say “group.to_component” to get an instance. This also magically creates and adds a component definition. Next - how do I use the Component Definition to create another instance of that definition? I want to generate lots of instances of that component without creating a new definition every time.
definition = model.definitions.add("my_new_definition")
definition.entities.add_face([-1,-1,0], [0,1,0], [1,-1,0])
10.times{ |i|
transformation = Geom::Transformation.translation([0,0,i])
model.entities.add_instance(definition, transformation)
}
See here in the SketchUp Ruby API documentation:
DefinitionList#add(name)
This is a direct way to create a new instance without going over a group.
Entities#add_instance(definition, transformation)
An entities collection has all kinds of methods of the form add_{entity}
to insert various entities into it.
WoW!! that woke me up. I didn’t pay enough attention to entities. Now I am out of the box. thanks.
Thank you. I just recoded everything - much neater now. You got me to think
outside the box and move up to the entities instead of staring at the
definition. I have been studying Sketchup and Ruby for about 3 months now
(part time) and am writing lots of examples that show what happens and how
things are related.
Now I can get on with my project.
Brad Denniston
408-892-4544