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

    Shuffle-ruby script?

    Scheduled Pinned Locked Moved Developers' Forum
    15 Posts 5 Posters 2.1k Views 5 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.
    • M Offline
      miikka1978
      last edited by

      Is there ruby script like Shuffle?
      I am quite often drawing shipping container stacks. Usually container stacks are full of different containers and it takes a lot of time to make the containers stacks look real (place containers random on top of each other). Is there a ruby script that would shuffle different components (containers) that have the same dimensions into a random order without changing the overall form of the container stack?


      Container stacks.jpg

      1 Reply Last reply Reply Quote 0
      • T Offline
        todd burch
        last edited by

        Do you mean, randomly change the color/material of a bunch of groups or components?

        Todd

        1 Reply Last reply Reply Quote 0
        • M Offline
          miikka1978
          last edited by

          Todd,
          Thank you for showing interest! Sorry that my explanation was not so clear. I try again. Lets say that I have 3 components (container blue, container white, container red). All these components have a certain texture. I would like to create a container stack that consists of these 3 components randomly placed in the stack. These containers should be on top of each other and the stack can't be higher than 5 containers high. In the real world, there is a space between containers. Some cases this space is 20 cm and some cases 40 cm.

          Usually I have used MatrixProximity script to create container stacks and then I have deleted some containers to make container stack uneven/random. Anyway, by using MatrixProximity script I have only been able to create container stacks that consist of one kind of containers. Therefore, I was hoping that there is already a script that would randomly change the places between certain components that have same dimensions. In this case I would create a container stack (see the picture) of 3 different components (containers) with a certain spaces between components, run the script to randomly change the places of these components and then delete some of the components to make the stack uneven. The result would be something like in the second picture.

          I hope this explanation is little more clear than the previous one.


          Container stacks2.jpg


          Container stacks3.jpg

          1 Reply Last reply Reply Quote 0
          • G Offline
            GreyHead
            last edited by

            I think you ought to be able to do the random part of this using the Proximity Components part of Matrix Proximity. Putting the three different colored containers into the Proximity Containers folder should trigger an option to randomise.

            @unknownuser said:

            The matrix copied component might belong to a Proximity Component ‘family’ (one of the trio-sets – typically the ‘Far’ type – see later). If so then Matrix realises this and looks for related family components of the same type (e.g. Far) that are already made within or loaded into the model or are in the Proximity Components folder. If it finds them a dialog tells you how many alternatives are available for use and asks if you want to swap and
            randomly scatter them within the matrix copies (this is in approximately equal proportions). This is useful for introducing randomness and naturalness into groups of trees etc – use a Proximity Component family ‘Far’ tree to make the matrix initially (e.g. tree-001-) and if you have say three others available tree-002-, tree-003- and tree-004- then the result would be a randomized mix of the four types.

            I also wondered if a fourth container with zero height - a flat plane might let the others drop - I don't think so, but perhaps if you turned Sketchy Physic on . . .

            Unfortunately I cant test as I get an error message with the version of Matrix Proximity I downloaded
            @unknownuser said:

            "Error: #<Errno::ENOENT: No such file or directory - F:/PROGRA~1/Google/GOOGLE~2Components\Proximity Components>"

            • there's a slash missing and I can't see how to fix it 😞

            Bob

            1 Reply Last reply Reply Quote 0
            • G Offline
              GreyHead
              last edited by

              With a little de-bugging and a lot of trial and error the MatrixProximity shuffle works nicely.

              Create a 'Components/Proximity Components' folder and save copies of unique components into it. Mine were named 'container-001-.skp' 'container-002-.skp' & 'container-003-.skp'

              Create a new SketchUp drawing with only one container in it (the shuffle will not work if the proxy containers are already in the drawing).

              Create your stack and, if all is well, you will see a second dialogue asking you if you want to Merge copies of the other components. Say Yes.

              I had to make a couple of small changes to the script to get round the Error message below. If you need them I'll post them here.

              Bob

              PS Creating 'zero-height' containers and adding them to the mix worked well. Using Sketchy Physics to drop the columns was a spectacular disaster . . .

              container.png

              1 Reply Last reply Reply Quote 0
              • M Offline
                miikka1978
                last edited by

                Thank you for the help. I am still having some problems. I never get the dialog that asks to merge copies.

                I have Proximity Components folder in this path (C:\Program Files\Google\Google SketchUp 6\Components\Proximity Components) and I have named containers (cont-001-,cont-002-,cont-003-,cont-004-). I have taken the cont-001- and placed it in the drawing => run the Matrix => I get multible copies => I get dialog that asks if I want to drop the componets onto nearest faces => but after that I never get any dialog to asks to merge copies. I have tried this same workflow with components that were alrady in the Proximity Components folder but still it does not ask to merge copies.

                Do you have any idea what could be the problem?

                1 Reply Last reply Reply Quote 0
                • G Offline
                  GreyHead
                  last edited by

                  The problem that I found was that the script wasn't able to open the sub-folder. When I open the RubyScript console I saw an error at line 415 (or thereabouts).

                  There is a line that reads something like:

                  proxdir = (Sketchup.find_support_file "", "Components/Proximity Components/") + "Components//Proximity Components//"
                  

                  I replaced this with two lines:

                  proxdir_1 = Sketchup.find_support_file "", "Components/Proximity Components/"
                  proxdir = proxdir_1 + "/Components/Proximity Components/"
                  

                  Bob

                  1 Reply Last reply Reply Quote 0
                  • M Offline
                    miikka1978
                    last edited by

                    Thank you for helping me. Now it works perfect. 😄

                    1 Reply Last reply Reply Quote 0
                    • G Offline
                      GreyHead
                      last edited by

                      Couldn't resist it. Here's a hacked version of the script that adds a 'Density' value to the dialogue box. The image below is at 85% which is the default (change this at line 234 to your preference).

                      Bob

                      container-3.png


                      Back up the original version and copy this to PlugIns folder.

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        todd burch
                        last edited by

                        Thanks for saving me some work Greyhead! (from one soon to be grey head to another!)

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

                          Thanks GreyHead for the error report*. It's over 2 years since the MatrixProximity code was last looked at by me !

                          Here's the 'official' Update v1.7 - http://www.sketchucation.com/forums/scf/viewtopic.php?p=46802#p46802

                          Note that GreyHead's changed version two posts below has some menu problems in it...

                          You might want to hack out his "density" bits if they are useful and add them back in ?

                          This fixes those AND the error* problem, with it finding the right directory - caused by changes to the way Ruby 'now' returns the FindFile path with/without a / at the end of a directory... [actually it changed ages ago, but I never caught it...]

                          Sorry for the slow response...

                          TIG

                          1 Reply Last reply Reply Quote 0
                          • G Offline
                            GreyHead
                            last edited by

                            Thanks TIG - the density bit was very much a hack. More a learning experiment than serious coding. (Though I was quite impressed with myself that I got it to work at all!)

                            I forgot that I'd commented out the menu entries 😞 - is there a way of editing and rerunning a script that's loaded into a menu without re-starting Sketchup?

                            Bob

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

                              @greyhead said:

                              Thanks TIG - the density bit was very much a hack. More a learning experiment than serious coding. (Though I was quite impressed with myself that I got it to work at all!)

                              I forgot that I'd commented out the menu entries 😞 - is there a way of editing and rerunning a script that's loaded into a menu without re-starting Sketchup?

                              Bob

                              Easy: type, 'load "script_name.rb"', into the Ruby console - it will reload the script completely. You need the 'load menu if script not loaded' test bits at the end - or else you'll get multiple menu entries - even then the latest menu entry's on the end ! - but most scripters add that test in anyway...

                              All /Plugins/ .rb files load automatically at startup, but you can also load any .rb files that have a .txt suffix at any time by using the, 'load "file.txt"' method - that's useful for rarely used scripts that you wouldn't want cluttering things up all the time...

                              .

                              IF the 'density' bit is thought useful I could add it into the 'official' version... Comments please...

                              TIG

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

                                @TIG: I'd rather use randomselect in this case 👍

                                1 Reply Last reply Reply Quote 0
                                • M Offline
                                  miikka1978
                                  last edited by

                                  For my purpose/need this density function is just perfect. Thanks again GreyHead! But right now I can't think any other way to benefit from this function when using MatrixProximity script. I will be fine with this unofficial version.

                                  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