The API docs misstate the acceptable arguments to add_group. It can be an Entity, a list of Entities, or an array of Entities. The model’s Entities collection is none of those. So,
In your first two examples, you need to convert the entities collection into an array using #to_a
In third example, you have created an Array with entities.count nil objects in it and then pushed Entities onto the end of it. Push appends without changing the original contents, so all those nils are still present. To create an empty array, use
IF the some_entities_context if not the Sketchup.active_model.active_entitiesAND the array_of_entities is also entirely composed of ‘entities’ in that exact same context.
A sure-fired way to make a Bugslplat is to ‘cross-thread’ the entities_context and the listed_entities…
The normal way to use add_group() is NOT to make a new group from [‘pre]selected’ entities; but rather to make a new empty group and then add your new entities directly into it…
And so on…
NOTE: you need to avoid making the empty group too soon, because SketchUp’s “Garbage Collection” deletes any empty definitions [groups/components], so try to make it and add entities into its entities context shortly afterwards…
Sometines we insert a temporary CPoint into the new group to keep it from getting GC’d too soon. (Then remove it at the end of your code that adds objects to the new group.)