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

    Newbie to Sketchup / Ruby

    Scheduled Pinned Locked Moved Developers' Forum
    12 Posts 5 Posters 1.8k 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.
    • thomthomT Offline
      thomthom
      last edited by

      Check out the Optimization sticky thread for various optimizations within SketchUp Ruby: http://forums.sketchucation.com/viewtopic.php?f=180&t=25305

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

      1 Reply Last reply Reply Quote 0
      • B Offline
        BillM
        last edited by

        Thanks for your replies
        Below is a example of one truss. This will run execute very quickly but I do have models with many trusses that take a while to execute.

        I take your point about making the plates components as these are inventory type items but the truss beams/pieces are mostly unique with different lengths, cuts etc..

        I did do a simple test with a script that just adds a few hundred empty groups. This also ran very slowly.

        I've attached the script that creates this. Please excuse any bad coding practices this is my first attemp at SU and Ruby.

        Thanks

        https://lh4.googleusercontent.com/-zvWoUxX4Xtw/TgsU01FNqpI/AAAAAAAAABE/VeWPN91JCag/s800/SUTruss.JPG


        Ruby script for Truss

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

          Looking at the code now.

          One thing I'd strongly recommend is wrap all your code into a module with a unique name. Otherwise it's all added to the global namespace and you risk conflicting with other plugins that doesn't use namespaces.

          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

            <span class="syntaxdefault"><br />def&nbsp;draw_face</span><span class="syntaxkeyword">(&nbsp;</span><span class="syntaxdefault">group</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">points&nbsp;</span><span class="syntaxkeyword">)<br />&nbsp;&nbsp;</span><span class="syntaxdefault">entities&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">group</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities<br />&nbsp;&nbsp;entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_face&nbsp;points<br />end<br /></span>
            

            Why do you use a wrapper like this? It's add a lot of unnecessary method calls and object creations.

            Instead of

            <span class="syntaxdefault"><br />grouppiece&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">grouppieces</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_group<br />grouppiece</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">name&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxstring">"T1"<br /></span><span class="syntaxdefault">points&nbsp;</span><span class="syntaxkeyword">=&nbsp;[...]<br /></span><span class="syntaxdefault">draw_face</span><span class="syntaxkeyword">(&nbsp;</span><span class="syntaxdefault">grouppiece</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">points&nbsp;</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">points&nbsp;</span><span class="syntaxkeyword">=&nbsp;[...]<br /></span><span class="syntaxdefault">draw_face</span><span class="syntaxkeyword">(&nbsp;</span><span class="syntaxdefault">grouppiece</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">points&nbsp;</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">points&nbsp;</span><span class="syntaxkeyword">=&nbsp;[...]<br /></span><span class="syntaxdefault">draw_face</span><span class="syntaxkeyword">(&nbsp;</span><span class="syntaxdefault">grouppiece</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">points&nbsp;</span><span class="syntaxkeyword">)<br />...<br />&nbsp;</span><span class="syntaxdefault"></span>
            

            do this:

            <span class="syntaxdefault"><br />grouppiece&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">grouppieces</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_group<br />grouppiece</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">name&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxstring">"T1"<br /></span><span class="syntaxdefault">ents&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">grouppiece</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities<br />points&nbsp;</span><span class="syntaxkeyword">=&nbsp;[...]<br /></span><span class="syntaxdefault">ents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_face</span><span class="syntaxkeyword">(&nbsp;</span><span class="syntaxdefault">points&nbsp;</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">points&nbsp;</span><span class="syntaxkeyword">=&nbsp;[...]<br /></span><span class="syntaxdefault">ents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_face</span><span class="syntaxkeyword">(&nbsp;</span><span class="syntaxdefault">points&nbsp;</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">points&nbsp;</span><span class="syntaxkeyword">=&nbsp;[...]<br /></span><span class="syntaxdefault">ents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_face</span><span class="syntaxkeyword">(&nbsp;</span><span class="syntaxdefault">points&nbsp;</span><span class="syntaxkeyword">)<br />...<br />&nbsp;</span><span class="syntaxdefault"></span>
            

            Should increase some performance. Though probably not greatly. But if you are running thousands of iterations - which it sound you might do - it could help some.

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

            1 Reply Last reply Reply Quote 0
            • B Offline
              BillM
              last edited by

              I've tried these small changes but it still looks like the number of groups is causing the speed issue.
              An example script with piece and plate groups defined take 55 sec to execute and 5 sec without these groups defined. This has the same number of faces etc just many more groups.

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

                There are typically 8 timber 'groups' in a truss - 2 rafters, 1or2 ties, 2x2 struts etc - probably one of each type.
                There are perhaps 4/5 different plate components in a truss - several of each; make a set of standard plates as SKPs and load/insert these as needed.
                Make each type of truss as a component and insert multiple instances of it at the centers needed along the wall-plate.
                You seem to be drawing all the trusses' timber-parts' faces... draw one vertical face and then push pull it to suit the timber's thickness.
                It shouldn't take that long to process this type of thing - it's relatively simple...

                TIG

                1 Reply Last reply Reply Quote 0
                • K Offline
                  kwalkerman
                  last edited by

                  What about wrapping everything with "start_operation" and "commit_operation"

                  (http://code.google.com/apis/sketchup/docs/ourdoc/model.html#start_operation)

                  this can significantly improve execution time as the model is not trying to track all the changes as they are made, but only updates once, when "commit_operation" is called.

                  --
                  Karen

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

                    @kwalkerman said:

                    What about wrapping everything with "start_operation" and "commit_operation"

                    (http://code.google.com/apis/sketchup/docs/ourdoc/model.html#start_operation)

                    this can significantly improve execution time as the model is not trying to track all the changes as they are made, but only updates once, when "commit_operation" is called.

                    --
                    Karen

                    Given that you use the disable_ui argument.

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

                    1 Reply Last reply Reply Quote 0
                    • B Offline
                      BillM
                      last edited by

                      Add update on the original problem with the speed import of Trusses into SU. I've done as TIG suggested making components of all pieces and plates that are the same even if there are in different trusses.
                      This has made a huge difference in speed as the number of groups has reduced. The import has gone from 55 secs to 4 secs.

                      Thanks for your help

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

                        Bill, Serge, Everyone - I've moved the Hotkeys discussion to a new topic. Keep on trussing.

                        Hi

                        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