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

    Quickly finding groups/comps in an Entity Collection?

    Scheduled Pinned Locked Moved Developers' Forum
    24 Posts 6 Posters 1.3k Views 6 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.
    • C Offline
      cjthompson
      last edited by

      this thread reminds me of this:
      http://refactormycode.com/codes/2-ruby-simple-loop
      with each consecutive code sample improving on the last πŸ˜†

      although the only improvement I could possibly add might be:

      
      def miner(ents)
          for e in ents
             if e.class==Sketchup;;Group or e.class==Sketchup;;ComponentInstance
                 miner(e.explode) 
             end
          end
      end
      
      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        Or to compact it as much as I can see, into a one-liner

        
        def xis(a);a.each{|e|xis(e.explode)if e.class==(Sketchup;;Group||Sketchup;;ComponentInstance)};end
        

        "xis" == e Xplode Instance S
        Usage: xis(entities)
        πŸ˜‰
        PS: a shorter way to do their puts 1 to 10 is this
        n=0;p n+=1while n<10
        πŸ˜’ ❓

        TIG

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          I take a few extra lines for readability any day.

          Thomas Thomassen β€” SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • J Offline
            Jim
            last edited by

            @thomthom said:

            I take a few extra lines for readability any day.

            True, but "squish-the-code" is a fun exercise and I often learn something new.

            
            def xis(a);a.map{|e|xis(e.explode)if e.respond_to?('move!')};end
            
            

            (assuming no one has added move! to any of the built-in classes!)

            Hi

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

            Advertisement