sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Auto group according to instance names

    Scheduled Pinned Locked Moved SketchUp Discussions
    sketchup
    9 Posts 4 Posters 969 Views 4 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
      pohlr1
      last edited by

      I am drawing homes in separate framing software then importing into sketchup, see attachment.

      What I really need is an addon that groups all the walls. I have attached a section of the house which is actually part of the garage, it contains 3 walls and I would like to group this as three groups automatically, it is not uncommon to have upwards of 100 walls. It would be additionally helpful if the new group contained the wall #.

      Any help would be much appreciated.


      GarageWalls.skp

      1 Reply Last reply Reply Quote 0
      • Dave RD Offline
        Dave R
        last edited by

        How would you expect SketchUp or an extension to identify the geometry that needs to be included in the group? What would you do, select the edges and faces that need to be grouped?

        Etaoin Shrdlu

        %

        (THERE'S NO PLACE LIKE)

        G28 X0.0 Y0.0 Z0.0

        M30

        %

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          Here's the outline of Ruby code to do this.
          Copey+paste all and run it in the Ruby Console.
          All matching elements are grouped by their group's name - say 'wall96'.
          It assumes that all of the grouped elements start say 'wall' and contain '-fram-'
          The current context must contain the elements.
          It's one step undo-able.

          model = Sketchup.active_model
          ents = model.active_entities
          groups = ents.grep(Sketchup;;Group).find_all{|e| e.name=~/^wall/ }
          walls=[]
          groups.each{|e| walls << e.name.split('-fram-')[0] }
          walls.uniq!
          walls.sort!
          model.start_operation('wall_grouper', true)
           walls.each{|w|
            puts w
            es = ents.find_all{|e| e.name =~ /^#{w}/ }
            gp = ents.add_group(es) if es[0]
            gp.name = w
           }
          model.commit_operation
          puts
          

          TIG

          1 Reply Last reply Reply Quote 0
          • P Offline
            pohlr1
            last edited by

            We are so close! It seems to be confusing wall 1 with wall 1xx or wall 1x. or wall 4 with wall 4x etc.

            The error I get is something like the following

            wall1
            wall100
            Error: #<NoMethodError: undefined method name=' for nil:NilClass> <main>:12:in block in <main>'
            <main>:8:in each' <main>:8:in <main>'
            SketchUp:1:in `eval'

            I attached the entire house this time.

            Thanks!


            westlakeframe.zip

            1 Reply Last reply Reply Quote 0
            • P Offline
              pohlr1
              last edited by

              @dave r said:

              How would you expect SketchUp or an extension to identify the geometry that needs to be included in the group? What would you do, select the edges and faces that need to be grouped?

              The geometry is all named by instance and the first "wallxxx" of the name is how I would prefer it to be grouped. I could do a search for wall1 then group all that then on and on but would take a very long time.

              1 Reply Last reply Reply Quote 0
              • S Offline
                slbaumgartner
                last edited by

                A minor error: in line 12 it should have been groups, not ents:

                
                model = Sketchup.active_model
                ents = model.active_entities
                groups = ents.grep(Sketchup;;Group).find_all{|e| e.name=~/^wall/ }
                walls=[]
                groups.each{|e| walls << e.name.split('-fram-')[0] }
                walls.uniq!
                walls.sort!
                model.start_operation('wall_grouper', true)
                 walls.each{|w|
                  puts w
                  es = groups.find_all{|e| e.name =~ /^#{w}/ } # error was here
                  gp = ents.add_group(es) if es[0]
                  gp.name = w
                 }
                model.commit_operation
                puts
                
                
                1 Reply Last reply Reply Quote 0
                • P Offline
                  pohlr1
                  last edited by

                  Thanks! It works seemlessly for the basement and 2nd floor then it coppies and moves things on the 1st floor. I have tried everything that I can think of. I have no idea what is causing this and was wondering if it was something simple. I attached the 1st floor if you get a minute. Thanks for everything.


                  WestLake1st.skp

                  1 Reply Last reply Reply Quote 0
                  • S Offline
                    slbaumgartner
                    last edited by

                    Another bug! Handling regular expressions can sometimes be subtle. Here it caused the operation to process any original groups with the same leading digits multiple times because it would match both wall1 and wall13 (etc.) when looking for things to group together. Processing more than once messed up the transformations that place objects in the model.

                    
                    model = Sketchup.active_model
                    ents = model.active_entities
                    groups = ents.grep(Sketchup;;Group).find_all{|e| e.name=~/^wall/ }
                    walls=[]
                    groups.each{|e| walls << e.name.split('-fram-')[0] }
                    walls.uniq!
                    walls.sort!
                    model.start_operation('wall_grouper', true)
                    walls.each{|w|
                      puts w
                      es = groups.find_all{|e| e.name =~ /^#{w}-/ } # both errors were here
                      gp = ents.add_group(es) if es[0]
                      gp.name = w
                    }
                    res = model.commit_operation
                    puts "operation committed = #{res}"
                    
                    
                    
                    1 Reply Last reply Reply Quote 0
                    • P Offline
                      pohlr1
                      last edited by

                      OK, now we are in business, thank you thank you, this is exactly what I need.

                      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