sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    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.
    • B Offline
      BillM
      last edited by

      Hi Everyone,

      I'm Bill from the UK and new to Sketchup.

      I'm currently a programmer for a truss rafter design program and started creating Ruby scripts from a .NET application that will create the truss geometry.It creates all the beams, nail plates etc that represent the truss in the model.

      Currently the truss is added as a component definition containing beam and plate groups. So we have a separate group for each beam and plate in the truss. Typically there can be up to 20 unique beams and plates per truss component definition. With many trusses it will result in many groups perhaps hundreds.
      The truss definitions may well be repeated as component instances in many locations throughout the model. With all these groups it has a dramatic effect on the execution on the script.

      To increase the speed I have changed the script so that I don't create separate groups for all the beams and plates. This speeds up the import greatly and the result is the same visually but I now don't have the beams and plates as groups for BOM and solid information. Once loaded into SU the speed is fine.

      As I am new to both SU and Ruby scripting is there anyway I can increase the speed of the script execution or is it just that I have so many groups defined. Any help greatly appreciated

      Thanks very much.

      Bill

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

        BillM

        I've moved this post the the Developers' forum - although you are a 'newbie' it'll get more exposure here...

        Firstly it'd be good if you could post an image of a typical 'trussed-rafter' and perhaps some code [use 'code' tags] so we can appreciate the issues better.
        Whenever you have a repeated object make a component-definition and place instances - this is the most efficient method. So each type of trussed-rafter, nail-plate etc can all be 'components'. The timber parts of the trusses will usually be too differing to allow the use of a component [although square-cut members could be 'componentized' and then scaled in their length?] - so the 'wood' can to be made as groups [note that these are only a special kind of definition/instance though]...
        Your code should make the trussed-rafter-component definition and then add instances/groups into its entities collection. Then place instances of the trussed-rafter-component as needed.
        Clearly the definitions of the nail-plates etc need to exist prior to you placing instances of them within a trussed-rafter-component definition...
        It sounds like you are already doing it much as I would approach it...
        Some examples will help us help you...

        TIG

        1 Reply Last reply Reply Quote 0
        • 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