Newbie to Sketchup / Ruby
-
Check out the Optimization sticky thread for various optimizations within SketchUp Ruby: http://forums.sketchucation.com/viewtopic.php?f=180&t=25305
-
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
-
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.
-
<span class="syntaxdefault"><br />def draw_face</span><span class="syntaxkeyword">( </span><span class="syntaxdefault">group</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">points </span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">entities </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">group</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities<br /> entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_face 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 </span><span class="syntaxkeyword">= </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 </span><span class="syntaxkeyword">= </span><span class="syntaxstring">"T1"<br /></span><span class="syntaxdefault">points </span><span class="syntaxkeyword">= [...]<br /></span><span class="syntaxdefault">draw_face</span><span class="syntaxkeyword">( </span><span class="syntaxdefault">grouppiece</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">points </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">points </span><span class="syntaxkeyword">= [...]<br /></span><span class="syntaxdefault">draw_face</span><span class="syntaxkeyword">( </span><span class="syntaxdefault">grouppiece</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">points </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">points </span><span class="syntaxkeyword">= [...]<br /></span><span class="syntaxdefault">draw_face</span><span class="syntaxkeyword">( </span><span class="syntaxdefault">grouppiece</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">points </span><span class="syntaxkeyword">)<br />...<br /> </span><span class="syntaxdefault"></span>
do this:
<span class="syntaxdefault"><br />grouppiece </span><span class="syntaxkeyword">= </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 </span><span class="syntaxkeyword">= </span><span class="syntaxstring">"T1"<br /></span><span class="syntaxdefault">ents </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">grouppiece</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities<br />points </span><span class="syntaxkeyword">= [...]<br /></span><span class="syntaxdefault">ents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_face</span><span class="syntaxkeyword">( </span><span class="syntaxdefault">points </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">points </span><span class="syntaxkeyword">= [...]<br /></span><span class="syntaxdefault">ents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_face</span><span class="syntaxkeyword">( </span><span class="syntaxdefault">points </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">points </span><span class="syntaxkeyword">= [...]<br /></span><span class="syntaxdefault">ents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_face</span><span class="syntaxkeyword">( </span><span class="syntaxdefault">points </span><span class="syntaxkeyword">)<br />...<br /> </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.
-
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. -
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... -
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 -
@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.
--
KarenGiven that you use the disable_ui argument.
-
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
-
Bill, Serge, Everyone - I've moved the Hotkeys discussion to a new topic. Keep on trussing.
Advertisement