# Instances, creation and changing

**URL:** <https://forums.sketchup.com/t/instances-creation-and-changing/7419>\
**Category:** Ruby API\
**Created:** [February 21, 2015, 1:43am UTC](https://forums.sketchup.com/t/instances-creation-and-changing/7419 "2015-02-21T01:43:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![braddenn](https://avatars.discourse-cdn.com/v4/letter/b/f05b48/32.png) [@braddenn](https://forums.sketchup.com/u/braddenn)\
**Post date:** [February 21, 2015, 1:43am UTC](https://forums.sketchup.com/t/instances-creation-and-changing/7419/1 "2015-02-21T01:43:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Aerilius](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@Aerilius](https://forums.sketchup.com/u/Aerilius)\
**Post date:** [February 21, 2015, 2:09am UTC](https://forums.sketchup.com/t/instances-creation-and-changing/7419/2 "2015-02-21T02:09:20Z")

</div>

```ruby
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)](http://www.sketchup.com/intl/en/developer/docs/ourdoc/definitionlist%23add)  
This is a direct way to create a new instance without going over a group.  
[Entities#add\_instance(definition, transformation)](http://www.sketchup.com/intl/en/developer/docs/ourdoc/entities%23add_instance)  
An entities collection has all kinds of methods of the form `add_{entity}` to insert various entities into it.

---

<div class="post-metadata">

**Author:** ![braddenn](https://avatars.discourse-cdn.com/v4/letter/b/f05b48/32.png) [@braddenn](https://forums.sketchup.com/u/braddenn)\
**Post date:** [February 21, 2015, 4:35am UTC](https://forums.sketchup.com/t/instances-creation-and-changing/7419/3 "2015-02-21T04:35:25Z")

</div>

WoW!! that woke me up. I didn’t pay enough attention to entities. Now I am out of the box. thanks.

---

<div class="post-metadata">

**Author:** ![braddenn](https://avatars.discourse-cdn.com/v4/letter/b/f05b48/32.png) [@braddenn](https://forums.sketchup.com/u/braddenn)\
**Post date:** [February 21, 2015, 6:04am UTC](https://forums.sketchup.com/t/instances-creation-and-changing/7419/4 "2015-02-21T06:04:40Z")

</div>

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
