Exploding a Parent with Children, The Children are selected after the operation - How to replicate with the API

If you select a parent and explode it via Edit>Group>Explode or Right-click>Explode, the children are selected after the operation.

If you use parent.explode the children are not selected.

How would you go about having the children selected after parent.explode ?

Will I have to iterate into the parent and get the child names?

The #explode method is used to explode the component instance into separate entities.

So you just need to pass it to selection…

An array of entity objects if successful, false if unsuccessful

Sketchup.active_model.selection.add( instance.explode )

or similar for groups:

Sketchup.active_model.selection.add( group.explode )

Almost right, but Selection#add throws a fit if the passed array has any Loop or EdgeUse objects, which #explode does return.

The Selection#add method’s error message is a bit misleading because loops and edge use objects are Sketchup::Entity subclass objects. Viz:

Error: #<TypeError: wrong argument type (expected Sketchup::Entity or Array of
<main>:in `add'

The #add method actually wants Sketchup::Drawingelement subclass objects, so we must filter other types out …

stuff = instance.explode.grep(Sketchup::Drawingelement)

Logged issue: