Create groups from entities in nested component

The code below will explode the component instance and group the resulting entities. Is this what you are asking for?

model = Sketchup.active_model
entities = model.active_entities
selection = model.selection
components = selection.grep(Sketchup::ComponentInstance)
new_groups = []

if components.empty?
  msg = 'Please select one or more Component Instance before using this tool.'
  UI.messagebox(msg, MB_OK)
  return
end

msg = 'Are you sure want to convert selected Component Instances to Group?'
result = UI.messagebox(msg, MB_YESNO)
if result == IDYES
  components.each do |instance|
    selection.clear
    result = instance.explode
    result.each do |entity|
      if entity.class.superclass == Sketchup::Drawingelement
        selection.add(entity)
      end
    end
    new_group = entities.add_group(selection)
    selection.add(new_group)
    new_groups << new_group
  end
 
  selection.add(new_groups)
end

I created a topic for an extension I was working for called Regroup where I wanted to explode groups and regroup them to fix the local axis. However, after the feedback, I am now fixing the local axis without the need for exploding groups or components.

Anyways here is the topic URL: SketchUp Extension: Regroup

1 Like