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

    Help with grouping groups

    Scheduled Pinned Locked Moved Developers' Forum
    17 Posts 2 Posters 729 Views 2 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.
    • honoluludesktopH Offline
      honoluludesktop
      last edited by

      I am trying to group other groups. So, the following to create an array of groups:

      group = @entities.add_group(new_group)
      @all_groups.push group
      

      The code below worked with edges and faces, but when written to group groups it fails at new_group = sel_ents[0].all_connected

      sel = @group_all
      sel_ents = sel.to_a
      first_entity = sel_ents[0]
      while sel_ents.length > 0
        if (sel_ents[0].is_a? Sketchup;;Group) and sel_ents[0] == first_entity
          new_group = sel_ents[0].all_connected
          sel_ents = sel_ents - new_group
          big_group = @entities.add_group(new_group)
        else
          sel_ents1 = sel_ents - [sel_ents[0]]
        end
      end
      model.commit_operation
      
      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        Groups doesn't have an .all_connected method.

        Is this geometry created by your script earlier? Or is it geometry modelled by the user which you want to group via your Ruby?

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

        1 Reply Last reply Reply Quote 0
        • honoluludesktopH Offline
          honoluludesktop
          last edited by

          It's created by my script.

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

            When you create geometry while modelling you draw the geometry first, like a face, then group it.

            But, when you build geometry via the API, create the group first and then the geometry directly inside it.

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

            1 Reply Last reply Reply Quote 0
            • honoluludesktopH Offline
              honoluludesktop
              last edited by

              OK, let me run with that for a while. Do you mean something like:
              group = entities.add_group group.add_line . . .
              Shoots its 3:30 am, I better go to bed, and get back to this tomorrow. Anything you can post to help me is appreciated. Good night:-)

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

                Yes, like that.

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

                1 Reply Last reply Reply Quote 0
                • honoluludesktopH Offline
                  honoluludesktop
                  last edited by

                  I think I get my problem. I am trying to use one procedure group1 = @entities.add_group(@selection) to create all my groups, and maybe I can't. If I can't, how do I create a different groupX where X is the times I come back to make a new group.

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

                    You lost me a bit..
                    there should be no limit to how many entities you can add to a group.

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

                    1 Reply Last reply Reply Quote 0
                    • honoluludesktopH Offline
                      honoluludesktop
                      last edited by

                      No that's not what I meant. How can the following proc_1 be called multiple times to create a different group each time its called? The following doesn't work, yes?

                      def main
                        aFile.each do |e|
                          proc_1
                          proc_1
                        end
                      end
                      def proc_1
                        group1 = @entities.add_group
                      end
                      
                      1 Reply Last reply Reply Quote 0
                      • thomthomT Offline
                        thomthom
                        last edited by

                        That will create a different group.

                        This will also create new groups
                        group1 = @entities.add_group group1 = @entities.add_group group1 = @entities.add_group

                        All this is doing is setting group1 to refer to the new group you create each time you call .add_group

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

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

                          proc_1 does nothing.

                          
                          def proc_1
                            group_1 = @entities.add_group
                            list_of_groups.push group_1
                          end
                          
                          

                          You're creating a group
                          then adding the reference to that group to a non-existent array list_of_groups

                          list_of_groups in main has no relationship with list_of_groups in proc_1.

                          Have you looked up in Ruby how arguments and return values work? And variable scope? It's some fundamental concepts to programming.

                          I was a about post an example of what you can do, but I'm not sure what you intend with the code.
                          You are reading a file, and for each line you want to add a group to a bigger group?

                          
                          def main
                            big_group = @entities.add_group
                            aFile.each do |e|
                              sub_group = big_group.add_group()
                              # now you can add entities to the sub-group
                              sub_group.entities.add_face(...)
                              sub_group.entities.add_line(...)
                            end
                          end
                          
                          

                          ?

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

                          1 Reply Last reply Reply Quote 0
                          • honoluludesktopH Offline
                            honoluludesktop
                            last edited by

                            Ok, so how are the different groups placed in a big_group? My attempt fails at the 6th lines.

                            def main
                              big_group = @entities.add_group #do I need?
                              aFile.each do |e|
                                proc_1
                                proc_1
                                big_group.add_group(list_of_groups)#fails?
                              end
                            end
                            
                            def proc_1
                              group_1 = @entities.add_group
                              list_of_groups.push group_1
                            end
                            

                            The following works with all Sketchup::Entity except for Sketchup::Group

                            def main
                              aFile.each do |e|
                                proc_1
                                proc_1
                                #following works except for adding groups
                                @entities.add_group(list_of_groups)
                              end
                            end
                            
                            def proc_1
                              group_1 = @entities.add_group
                              list_of_groups.push group_1
                            end
                            
                            1 Reply Last reply Reply Quote 0
                            • honoluludesktopH Offline
                              honoluludesktop
                              last edited by

                              I am reading a Cad file of entities, making SU entities from that list. Some of the entities are Cad blocks (a bunch of Cad entities), that I am trying to turn into SU Group(s)
                              temp05.jpg
                              I can insert and group, edges and faces, but not groups.

                              1 Reply Last reply Reply Quote 0
                              • honoluludesktopH Offline
                                honoluludesktop
                                last edited by

                                Well, I made it work in the web console, now back to the program.

                                ` model = Sketchup.active_model
                                entities = model.active_entities

                                master_group = []

                                point1 = Geom::Point3d.new(0,0,0)
                                point2 = Geom::Point3d.new(20,20,0)
                                point3 = Geom::Point3d.new(10,10,0)
                                point4 = Geom::Point3d.new(30,30,0)
                                point5 = Geom::Point3d.new(10,30,0)

                                line1 = entities.add_line point1,point2
                                group1 = entities.add_group line1
                                master_group.push group1

                                line2 = entities.add_line point3,point4
                                group2 = entities.add_group line2
                                master_group.push group2

                                line3 = entities.add_line point3,point5
                                master_group.push line3

                                entities.add_group(master_group)`


                                edit master_group, select group1

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

                                  When you model you draw face/line - then group.
                                  But when you build geometry with the API, make the group first and then add the geometry directly inside the group - instead of moving it afterwards which is prone to crashes.

                                  ` model = Sketchup.active_model
                                  entities = model.active_entities

                                  master_group = entities.add_group

                                  point1 = Geom::Point3d.new(0,0,0)
                                  point2 = Geom::Point3d.new(20,20,0)
                                  point3 = Geom::Point3d.new(10,10,0)
                                  point4 = Geom::Point3d.new(30,30,0)
                                  point5 = Geom::Point3d.new(10,30,0)

                                  group1 = master_group.entities.add_group
                                  line1 = group1.entities.add_line(point1,point2)

                                  group2 = master_group.entities.add_group
                                  line2 = group1.entities.add_line(point3,point4)

                                  group3 = master_group.entities.add_group
                                  line3 = group3.entities.add_line(point3,point5)`

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

                                  1 Reply Last reply Reply Quote 0
                                  • honoluludesktopH Offline
                                    honoluludesktop
                                    last edited by

                                    Yes, I read something about that in the API, but I thought that was a problem for SU versions prior to 8.0. Anyway, I wouldn't have been able to do it without your help, thanks.

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

                                      It is safer in any case - as you don't risk your edges/faces merging with stuff it should not merge with.

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

                                      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