Select all sub-components in a selection

This is quite easy to do but in most cases a bad idea. The user will not expect entities outside of the active drawing context to be selected. In my view this should only be done in the extreme case when the whole point of the plugin is to be able to select outside the current drawing context. If the purpose of the plugin is something else it’s better to find another solution.

# Select an instance and run snippet to select all child instances.
def select_children(instance)
  children = instance.definition.entities.select { |e| e.respond_to?(:definition) }
  instance.model.selection.add(children)
  children.each { |c| select_children(c) }
end

select_children(Sketchup.active_model.selection.first)