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

    Group components from array

    Scheduled Pinned Locked Moved Developers' Forum
    13 Posts 4 Posters 541 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.
    • H Offline
      HPW
      last edited by

      But waht about the quote in the doc:

      @unknownuser said:

      NOTE: calling add_group with entities in its parameters has been known to crash SketchUp. It is preferable to create an empty group and then add things to its Entities collection.

      1 Reply Last reply Reply Quote 0
      • H Offline
        HPW
        last edited by

        Anyway I give it a try and it works nicely.

        
          grouplist.each{|c|
           str = '@my_group_list = GroupPrefix'+ c
           eval str
           group = entities.add_group(@my_group_list)
           group.name = '<['+c.rjust(5)+'>'
          }
        
        

        By the way: Is there a better way to create dynamicly array names and recall them?

        The Grouplist is an array of strings like [ "100" "200" ...]
        The Group-arrays are like 'GroupPrefix100' etc.

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

          Ruby is kind of cool in that you can increment Strings.

          
          name = "Group100"
          name.next #(also .next! and .succ & .succ!)
          ==> "Group101"
          
          

          Maybe useful?

          Hi

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

            @hpw said:

            But waht about the quote in the doc:

            @unknownuser said:

            NOTE: calling add_group with entities in its parameters has been known to crash SketchUp. It is preferable to create an empty group and then add things to its Entities collection.

            Yea, I've asked about that myself, but I've yet to hear about any concrete examples where it fails. And I don't know how you would move existing geometry into a group without rebuilding it from scratch.

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

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

              group=Sketchup.active_model.active_entities.add_group()
              ### now we must assume you have an array of instances...
              instances.each{|instance|
                group.entities.add_instance(instance.definition,instance.transformation)
                instance.erase!
                ### remove the original instance - it's now been repeated in the group...
              }
              
              

              I think this is what you want ?

              TIG

              1 Reply Last reply Reply Quote 0
              • H Offline
                HPW
                last edited by

                @unknownuser said:

                I think this is what you want ?

                Thanks TIG, works also nicely.
                But what is now the better or safer solution?

                Hans-Peter

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

                  @unknownuser said:

                  But what is now the better or safer solution?
                  Why, mine of course ! πŸ˜‰

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • H Offline
                    HPW
                    last edited by

                    Very convincing reason!
                    πŸ˜‰
                    But is the warning in the doc correct of from an older version of SU.
                    Both shows me an identical result.
                    The first version is one code-line shorter.

                    1 Reply Last reply Reply Quote 0
                    • H Offline
                      HPW
                      last edited by

                      Another observation: The first solution seems much faster.
                      When I leave the outliner open and run the code, the outliner flickers as long the code run.
                      But the first is much faster than the second one.

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

                        Having the Outliner open during script execution is risky as it can cause crashes when groups/instances are getting changed...

                        Adding stuff to groups immediately as they are made, in scripts can cause crashes, although I often do it - safest not to... Do whatever works for you best...

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • H Offline
                          HPW
                          last edited by

                          @unknownuser said:

                          Ruby is kind of cool in that you can increment Strings.

                          Thanks Jim for the tip.

                          In this case I can not use it, since my block-numbering-steps comes from the imported autocad-blocknames.
                          But maybe it gets usefull in the future.

                          @unknownuser said:

                          Do whatever works for you best...

                          Thanks again TIG.

                          Hans-Peter

                          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