sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    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.
    • pingpinkP Offline
      pingpink
      last edited by

      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
      • TIGT Offline
        TIG Moderator
        last edited by

        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
        • pingpinkP Offline
          pingpink
          last edited by

          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
          • TIGT Offline
            TIG Moderator
            last edited by

            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

              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
              • pingpinkP Offline
                pingpink
                last edited by

                β˜€

                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
                • pingpinkP Offline
                  pingpink
                  last edited by

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

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

                  Advertisement