# SketchUp quickly deletes empty groups

**URL:** <https://forums.sketchup.com/t/sketchup-quickly-deletes-empty-groups/23014>\
**Category:** Ruby API\
**Created:** [April 2, 2016, 4:09pm UTC](https://forums.sketchup.com/t/sketchup-quickly-deletes-empty-groups/23014 "2016-04-02T16:09:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephenwhamilton](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@stephenwhamilton](https://forums.sketchup.com/u/stephenwhamilton)\
**Post date:** [April 2, 2016, 4:09pm UTC](https://forums.sketchup.com/t/sketchup-quickly-deletes-empty-groups/23014/1 "2016-04-02T16:09:31Z")

</div>

I have discovered a surprising API behavior, and would like it confirmed as either a bug or as intended. I’m using Sketchup Make version 15.3.31 64-bit on a win7 PC (in case that matters). I have put off the 2016 update because i was mid-project.

I have ruby code that executes a model construction algorithmicly. The algorithm first creates the model hierarchy as a set of empty groups, and then goes back and adds content to each group. The algorithm is failing because when it adds a face to one group and pushpulls it into 3d, empty peer groups are deleted. So when the code reaches a peer group there is no group to receive its content.

I find this behavior quite odd, and of course for me highly undesirable. But, as often is the case, i’m sure i don’t have the whole picture. I created a short example script to demonstrate the problem. It is included here. You can just “load surprise\_demo.rb” from the Sketchup console to execute it.

[surprise\_demo.rb](https://forums.sketchup.com/uploads/short-url/3zEgIrOCnSNTyvV7ED2q1Xo8Ks2.rb) (3.1 KB)

Thanks in advance for the help from you more experienced, knowledgeable, and generous ones. I have always found this forum to be a great resource for cases such as this.

---

<div class="post-metadata">

**Author:** ![jim\_foltz](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/jim_foltz/32/74787_2.png) [@jim\_foltz](https://forums.sketchup.com/u/jim_foltz)\
**Post date:** [April 2, 2016, 4:18pm UTC](https://forums.sketchup.com/t/sketchup-quickly-deletes-empty-groups/23014/2 "2016-04-02T16:18:08Z")

</div>

Bug or not, that’s just how SketchUp works.

You can either add a cpoint to the Groups at the moment you create them, or do not create the Groups until the moment you are ready to add geometry to them.

---

<div class="post-metadata">

**Author:** ![slbaumgartner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/32/7302_2.png) [@slbaumgartner](https://forums.sketchup.com/u/slbaumgartner)\
**Post date:** [April 2, 2016, 4:18pm UTC](https://forums.sketchup.com/t/sketchup-quickly-deletes-empty-groups/23014/3 "2016-04-02T16:18:16Z")

</div>

This is a known (though for some reason less widely than it should be) problem. The garbage collector is aggressive about reclaiming empty groups. If you want to keep a group alive for more than an instant, you have to put _something_ in it immediately!

Jim got there first!

---

<div class="post-metadata">

**Author:** ![stephenwhamilton](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@stephenwhamilton](https://forums.sketchup.com/u/stephenwhamilton)\
**Post date:** [April 2, 2016, 4:25pm UTC](https://forums.sketchup.com/t/sketchup-quickly-deletes-empty-groups/23014/4 "2016-04-02T16:25:37Z")

</div>

Wow ! This response time is incredible.  
The cpoint may be an acceptable answer for me. Thanks for the idea.

and thanks to slbaumgartner too.

---

<div class="post-metadata">

**Author:** ![slbaumgartner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/32/7302_2.png) [@slbaumgartner](https://forums.sketchup.com/u/slbaumgartner)\
**Post date:** [April 2, 2016, 4:43pm UTC](https://forums.sketchup.com/t/sketchup-quickly-deletes-empty-groups/23014/5 "2016-04-02T16:43:24Z")

</div>

The beauty of using a ConstructionPoint is that they are mainly for use by people while modeling, rarely needed in Ruby code. So, you can easily find and remove the cpoint after you have added some real geometry to the group:

`mygroup.entities.grep(Sketchup::ConstructionPoint)[0].erase!`
