Groups mysteriously deleted in an operation

My plugin loads geometry from a users file and creates SketchUp geometry in a single operation. All geometry is created in a SketchUp group, many groups can be created to hold all the geometry. For a few very complicated models, something is happening in the operation which causes all the groups and faces to be deleted. Entity observers for faces and groups created in the operation do not fire. Does anyone know what might be causing this?

It’s hard to say.

Modifying a collection while iterating over the collection may cause this type of error.

Modifying the model from within observer methods can cause problems. Check out the SketchUp safe observers repository on GitHub.

Can you post a minimal amount of code that shows this behavior?

Thanks Jim, I haven’t been able to fully reproduce this but it seems related to the following code. In this code, if I try to create a bad face in a group in an operation, the group is deleted. My code is failing when creating the surface ‘my_points’. This does not fail in my example, but in the real case there are other surfaces which may overlap or intersect the ‘my_points’ surface. The one clue I have is that when I pass in non-planar points to add_face it throws an exception. In my code, no exception is thrown when trying to create the ‘my_points’ face but add_face returns nil.

GroupTest.rb (3.2 KB)

On a quick glance, empty Groups get cleaned up by SketchUp fairly quickly if geometry is not added soon after creation. If geometry creation fails, the empty Group is getting deleted.

Here’s a link to another post: Empty groups get deleted?! • sketchUcation • 1

Thanks, I had seen that link which is why I was poking around with that in my test. The other odd thing (in addition to returning a null face without throwing an exception) about my failure (on the real model) is that ALL the groups in the model get deleted, not just the one containing bad geometry.

When I ran the code (order = 3), I DO get a face created:

face1 = #<Sketchup::Face:0x000000045c21d8>

For those who do not want to go off into other threads, in other websites,…

The answer is to immediately add a ConstructionPoint into the group keeping a reference to it. Then attempt to add other entities like faces. Check each entity afterward that it is not nil. If the operation is a success, delete the Cpoint.