# Inserting a group or component with Ruby API

**URL:** <https://forums.sketchup.com/t/inserting-a-group-or-component-with-ruby-api/114936>\
**Category:** Ruby API\
**Created:** [January 30, 2020, 11:07pm UTC](https://forums.sketchup.com/t/inserting-a-group-or-component-with-ruby-api/114936 "2020-01-30T23:07:47Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [January 31, 2020, 12:15am UTC](https://forums.sketchup.com/t/inserting-a-group-or-component-with-ruby-api/114936/2 "2020-01-31T00:15:35Z")

</div>

**(1)** A short piece of code (_snippet_) can be posted [correctly](https://forums.sketchup.com/t/how-to-colourize-code-on-the-forum-wiki/46189) in the forum.  
(I’m not going to download such a small file and open it in my code editor.)

**(2)** A group of **_what_**? All the entities you’ve created in the method ?  
If so, then do not add them to the **model’s** entities collection. Instead create a group or a component definition, and then add the geometry to their entities collection.

_from an example in the [`Sketchup::Group`](http://ruby.sketchup.com/Sketchup/Group.html) class documentation_ …

```ruby
# Add a group to the model.
group = Sketchup.active_model.entities.add_group
group.entities.add_line([0,0,0],[100,100,100])

```

You can also make a reference to the group’s entities collection object …

```ruby
# Add a group to the model:
group = Sketchup.active_model.entities.add_group
# Reference it's entities collection:
ents1 = group.entities
enst1.add_line([0,0,0],[100,100,100])

```

Be sure to quickly add drawingelements or objects to the group’s entities or the SketchUp engine will delete the groups “out from under you”.

Many coders immediately put a cpoint at the group’s origin to prevent SketchUp from deleting the group. …

```ruby
# Add a group to the model:
group = Sketchup.active_model.entities.add_group
# Reference it's entities collection:
ents1 = group.entities
# Add a guide point at the group's origin:
cpt = enst1.add_cpoint([0,0,0])

```

… then later after adding things to the group, they delete the guide point …

```ruby
cpt.erase!

```

---

_[View the full topic](https://forums.sketchup.com/t/inserting-a-group-or-component-with-ruby-api/114936)._
