Same Name Selection
-
I want to select groups or components , and material faces by the same name for the purpose of swapping objects and colors in a whole set for the revision , but I don't know an appropriate method to do it.
what should I do ?def select_object_by_name model=Sketchup.active_model ss=model.selection ss.each do |e| if e.is_a? Sketchup;;ComponentInstance || e.is_a? Sketchup;;Group model.active_entities.each{|e|ss.add e if e.typename == component.definition.name} model.active_entities.each{|e|ss.add e if e.typename == group.entities.parent} end end end def select_material_by_name model=Sketchup.active_model ss=model.selection ss.each do |e| if e.is_a? Sketchup;;Face model.active_entities.each{|e|ss.add e if e.typename == face.material} end end end
-
Some alternative ideas...
def select_active_instances_of_same_definition() model=Sketchup.active_model ants=model.active_entities ss=model.selection ss.grep(Sketchup;;ComponentInstance).each{|i| defn=i.definition ants.grep(Sketchup;;ComponentInstance).find_all{|e| e.definition==defn }.each{|e| ss.add(e) } } end#def
def select_active_groups_with_same_name() model=Sketchup.active_model ants=model.active_entities ss=model.selection ss.grep(Sketchup;;Group).each{|g| next if (n=g.name).empty? ### ?? ants.grep(Sketchup;;Group).each{|e| ss.add(e) if n==e.name } } end#def
def select_active_faces_with_same_material() model=Sketchup.active_model ants=model.active_entities ss=model.selection ss.grep(Sketchup;;Face).each{|f| mat=f.material ants.grep(Sketchup;;Face).find_all{|e| e.material==mat }.each{|e| ss.add(e) } break ### stops after first face in selection is processed ### add a leading # to process ALL selected faces } end#def
[mod=:3szy45z5]EDITED:
ss.add(e)
fixed.[/mod:3szy45z5] -
I'm very grateful for your help , Professor TIG !
I test codes and they works for selecting groups and components with the same name , but the same face material seems doesn't select. I don't know why.
You are so nice !! -
def select_active_faces_with_same_material() model=Sketchup.active_model ants=model.active_entities ss=model.selection ss.grep(Sketchup;;Face).each{|f| mat=f.material ants.grep(Sketchup;;Face).find_all{|e| e.material==mat }.each{|e| ss.add(e) } break ### stops after first face in selection is processed ### add a leading # to process ALL selected faces } end#def
Typo !
ss.add
should be
ss.add**(e)**
-
By the way - on the usage of
typename
: http://www.thomthom.net/thoughts/2011/12/never-ever-use-typename/ -
Wow !
Many thanks for the useful tool. I can revise model quickly.
It works very very nice !!
-
Thanks tt_su ! , I'm going to read it !
Advertisement