Deep Select/Selection Tools: Can we select every object in the model that has a the same material as selection?

I’m wanting to grab every object in the model that has the same material as what I have selected, and then delete them. How do I do it?

If you use the search option of the forum you would have found this:
http://sketchucation.com/forums/viewtopic.php?p=276175#p276175

:smiley:
Thank you, I will plan to do more research before making a new topic from now on, Lord willing.

Are you referring to the SketchUcation forum?

No, this one. The link came out of one of the topics found by the search…

Experimental! Not really tested. Use your own risk! Backup…backup…backup…
However it should work… :wink:

Copy-paste this snippet to Ruby Console and hit Enter (Return)
You will have a right click (context) menu if you select only one group or instance which have a material applied on:

"Delete all objects with same material."
You can undo it!

module Dezmo
  module DezmoDelSameMatObj_test

    extend self
    @@loaded = false unless defined?(@@loaded)
    
    def get_same_mat_instances(ents, instances = [])
      ents.each{|e|
        case e
        when Sketchup::ComponentInstance, Sketchup::Group
          instances<<e if e.material == @mat
          get_same_mat_instances(e.definition.entities, instances)
        end
      }
      instances
    end

    def del_same_mat
      model = Sketchup.active_model
      sel = model.selection
      @mat =  sel.first.material
      entities = model.entities
      to_erase = get_same_mat_instances(entities)
      count = to_erase.size
      model.start_operation('Delete same material objects', true)
      to_erase.to_a.each{ |e| e.erase! if e.valid?}
      model.commit_operation
      UI.messagebox("Object with #{@mat.name} material deleted: #{count}")
    end
    
    unless @@loaded
      UI.add_context_menu_handler{|menu|
        sel = Sketchup.active_model.selection
        if sel.single_object? && sel.first.material
          menu.add_item("Delete all objects with same material."){del_same_mat()}
        end
      }
      @@loaded = true
    end
    
  end
end

delsamematobj

Does exactly what it says. It will ignore objects that have their faces painted!
Awesome!
Now, what if I want it removed from my system and the context menu?

Just restart Sketchup.