Select all groups with the same material

Have you all played with AI Assistant in SketchUp 2026.1? With that you can ask a question like this:

“give me a ruby script that will select all groups and components that are using the same material“

It then gives you this:

model = Sketchup.active_model
materials = model.materials

# Prompt the user to select a material
material_names = materials.map(&:name)
selected_material_name = UI.inputbox(["Select Material:"], [material_names.first], "Material Selection")[0]

# Find the selected material
selected_material = materials[selected_material_name]

# Select all groups and components using the selected material
entities = model.active_entities
selection = model.selection
selection.clear

entities.each do |entity|
  if entity.is_a?(Sketchup::Group) || entity.is_a?(Sketchup::ComponentInstance)
    if entity.material == selected_material || entity.definition.material == selected_material
      selection.add(entity)
    end
  end
end


You put that into Ruby Console, and when the dialog comes up you change the text to be the name of the material you’re interested in. It then selects all groups and components that are painted with that material.

I revisited this project after a break to work on something else. I selected the whole model and exploded it. It took all morning for Sketchup to do, but it did eventually work. This meant each object was only one group deep and this script worked perfectly. The model has gone from over 215mb to 186mb and is much more usable. Thanks for you help.