• Login
sketchucation logo sketchucation
  • Login
โš ๏ธ Libfredo 15.4b | Minor release with bugfixes and improvements Update

Same Name Selection

Scheduled Pinned Locked Moved Developers' Forum
7 Posts 3 Posters 270 Views 3 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    pingpink
    last edited by 29 Nov 2013, 04:10

    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
    
    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 29 Nov 2013, 10:51

      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]

      TIG

      1 Reply Last reply Reply Quote 0
      • P Offline
        pingpink
        last edited by 29 Nov 2013, 13:08

        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 !! ๐Ÿ˜„

        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 29 Nov 2013, 13:23

          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)**
          ๐Ÿ˜’

          TIG

          1 Reply Last reply Reply Quote 0
          • tt_suT Offline
            tt_su
            last edited by 29 Nov 2013, 14:36

            By the way - on the usage of typename: http://www.thomthom.net/thoughts/2011/12/never-ever-use-typename/

            1 Reply Last reply Reply Quote 0
            • P Offline
              pingpink
              last edited by 29 Nov 2013, 14:53

              โ˜€

              Wow !

              Many thanks for the useful tool. I can revise model quickly.
              It works very very nice !!


              result picture

              1 Reply Last reply Reply Quote 0
              • P Offline
                pingpink
                last edited by 29 Nov 2013, 14:57

                Thanks tt_su ! , I'm going to read it !

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                1 / 1
                • First post
                  1/7
                  Last post
                Buy SketchPlus
                Buy SUbD
                Buy WrapR
                Buy eBook
                Buy Modelur
                Buy Vertex Tools
                Buy SketchCuisine
                Buy FormFonts

                Advertisement