SketchUp quickly deletes empty groups

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 (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.

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.

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!

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

and thanks to slbaumgartner too.

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!