Select all sub-components in a selection

Sorry for my long absence!

I was able to analyze in depth the many methods you provided me on this forum and SketchUcation.

Thanks to that, I achieved all my goals and more. :slight_smile:

Sorry john for the spaces in the code, I must be careful not to integrate the lines of codes in the language translator.

Thank you for your explanations and your example very detailed.

To solve the problem of deleting the dynamic attributes of all sub-components in a selection, I was inspired by a method provided by TIG in another example.

I used this same method to remove all hidden subcomponents.

To remove unnecessary components at the end of the project, I used john trick of naming components with a prefix.

To solve many other problems, I used the many methods provided by sdmitch in SketchUcation. ;-D

As promised here are some code examples that work:

def remove_all_sub_component_masks_in_the_selection(ents)
     sel = Sketchup.active_model.selection
     array = []
     ents.grep(Sketchup::ComponentInstance).each{|e|
     array << e
     remove_all_sub_component_masks_in_the_selection(e.definition.entities)
     }
     array.each{|i|
     i.erase! unless i.visible?
     }
     end 
	 
  def remove_all_sub_component_masks_in_the_selection_end
      mod = Sketchup.active_model
      ent = mod.active_entities
      sel = mod.selection
      instances = sel.grep(Sketchup::ComponentInstance)
      sel.clear
	  remove_all_sub_component_masks_in_the_selection(instances)
      end	

	  remove_all_sub_component_masks_in_the_selection_end

def remove_list_of_sub_components_with_prefix
    ["CLC2","0-DECO"].each{|name|
    match = /#{name}/i
    mod = Sketchup.active_model
    sel = mod.selection
	sel.grep(Sketchup::ComponentInstance).each{|s|s.definition.entities.grep(Sketchup::ComponentInstance).each{|e| e.erase! if e.definition.name =~ match }}}
    end	

    remove_list_of_sub_components_with_prefix