[Plugin] Boolean helper update 08122011
-
How is this plugin not called "ScaleUp.rb"?
-
@jim said:
How is this plugin not called "ScaleUp.rb"?
It's use is to quickly scale up and down a model. Why?
If one is working on small parts in SU for instance for 3d printing, some operations like the boolean operations and lathe result in errors with small vertices's/faces. SU has problems handling these small entities. If you temporarily scale up your model, you don't have these problems. After the operations are done , you can scale down again.So that's why the plugin is named booleanhelper. Simple but effective.
-
Jim's 'joke' refers to the fact that a lot of SketchUp tools have similar sounding names and you do 'ScaleUp' things using your tool - I suspect that it's 'lost in translation' ?
Another couple of things...
view.zoom_extents
must be
Sketchup.active_model.active_view.zoom_extents
as you haven't defined 'view' otherwise.
An alternative is
Sketchup.send_action("viewZoomExtents:")
a = Sketchup.read_default('liquidsscalefactor','value')
would be better to trap older wrong class-type values [your earlier version probably saved the value as the wrong 'type' - it should be saved as a 'String'] - like...
a = Sketchup.read_default('liquidsscalefactor','value'**,'100'**) if a.class==String a=a.to_f else ### might be an Array or something else! a=100.0 end#if
The basic Array class doesn't have '.to_f' as a method... although some scripts might extend that class methods and add it... and then there might not be an error like that, BUT best fixed in your code... -
@unknownuser said:
Oops!
Following error code on my machine.
Error Loading File booleanhelper1.05.rb
undefined method `to_f' for [10]:ArrayNotice, I have been following this thread not so much as I need the plugin, just trying to keep up with the programing.
Ken
Hi Ken,
Thanx for the feedback, Boolean helper writes the scalefactor to the registry. I think an old value from previous version sits there. To fix it
Copy this code:
Sketchup.write_default('liquidsscalefactor','value',100)
And paste it in your ruby-console, press Enter and restart SU, and let me know if it worked...
-
Please write/read your values as a String - '100' etc.
It's safest to be consistent.
I know and integer like 100 would be OK and make a float 100.0 but so would '100'...
As explained an Array like you tried initially [100] is likely to break it ! -
@ Jim, no i did not get your joke .... Lost in translation I suppose
I've set everything to string now:
<span class="syntaxdefault">require </span><span class="syntaxstring">'sketchup.rb'<br /><br /></span><span class="syntaxcomment">#=============================================================================<br /></span><span class="syntaxdefault"> <br /> <br /> </span><span class="syntaxcomment">#$booleanhelper_scaleoption = 1 # Uncomment the first line of code to scale your object about the origin. ( Restart needed!)<br /></span><span class="syntaxdefault"> <br /> </span><span class="syntaxcomment"># Leave it as it is to scale your object about it's center.<br /></span><span class="syntaxdefault"> <br /><br /><br /><br /><br />module Bhelper<br /><br /> sf </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">'100'<br /></span><span class="syntaxdefault"> if Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">read_default</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'liquidsscalefactor'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'value'</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> nil<br /> <br /> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">write_default</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'liquidsscalefactor'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'value'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">sf</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> <br /> end <br /> <br /> <br /> class Tltip<br /> <br /> def initialize</span><span class="syntaxkeyword">()<br /></span><span class="syntaxdefault"> <br /><br /> <br />a </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">read_default</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'liquidsscalefactor'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'value'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'100'</span><span class="syntaxkeyword">)<br /><br /></span><span class="syntaxdefault">if a</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">class </span><span class="syntaxkeyword">==</span><span class="syntaxdefault">String<br />a</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">a</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">to_f<br />else </span><span class="syntaxcomment">### might be an Array or something else!<br /></span><span class="syntaxdefault">a</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">100.0<br />end</span><span class="syntaxcomment">#if<br /><br /><br /><br /></span><span class="syntaxdefault">b </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> 1.0</span><span class="syntaxkeyword">/</span><span class="syntaxdefault">a<br />$cmdbooleanhelperscale</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">tooltip </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Scalefactor #{b}"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> if $cmdbooleanhelperscale<br />$cmdbooleanhelperscale1</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">tooltip </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Scalefactor #{a.to_i}"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> if $cmdbooleanhelperscale1<br />$cmdbooleanhelperscale</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">menu_text </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Scalefactor #{b}"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> if $cmdbooleanhelperscale<br />$cmdbooleanhelperscale1</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">menu_text </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Scalefactor #{b}"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> if $cmdbooleanhelperscale1<br /> end<br /> <br /> end<br /><br /><br />class Getinfo<br /> <br /> def initialize</span><span class="syntaxkeyword">()</span><span class="syntaxdefault"> <br /> <br /> <br /><br /> </span><span class="syntaxkeyword">@@</span><span class="syntaxdefault">sf </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">read_default</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'liquidsscalefactor'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'value'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'100'</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> <br /> prompts </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[</span><span class="syntaxstring">"Set scalefactor "</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> <br /> defaults </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[@@</span><span class="syntaxdefault">sf</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> values </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[</span><span class="syntaxstring">"10|100|1000"</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> </span><span class="syntaxcomment"># For other scale factors please use the native Sketchup-scale tool . This script is intended only for quick scale up and down actions .<br /><br /></span><span class="syntaxdefault"> <br /> results </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">inputbox prompts</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> defaults</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> values</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">"Scalefactor."<br /></span><span class="syntaxdefault"> <br /> return if not results<br /><br /> <br /> <br /> </span><span class="syntaxkeyword">@@</span><span class="syntaxdefault">sf </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> results</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">to_s<br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">write_default</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'liquidsscalefactor'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'value'</span><span class="syntaxkeyword">,@@</span><span class="syntaxdefault">sf</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> <br />Bhelper</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Tltip</span><span class="syntaxkeyword">.new()<br /><br /></span><span class="syntaxdefault"> <br /> <br /> end<br /><br />end<br /><br /><br /> <br /><br /><br />class Kleiner<br /> <br /> def initialize</span><span class="syntaxkeyword">()</span><span class="syntaxdefault"> <br /> sf </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">read_default </span><span class="syntaxstring">'liquidsscalefactor'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'value'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'100'</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">to_f<br /> <br /> model </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br /> entities </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_entities<br /> selection </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">selection<br /> <br /> boundbox </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">bounds<br /> center</span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> boundbox</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">center<br /><br /> <br /> if $booleanhelper_scaleoption </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> 1<br /> <br /> center </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> <br /> <br /> end <br /> <br /> trans </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Transformation</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">scaling</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">center</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 1.0</span><span class="syntaxkeyword">/</span><span class="syntaxdefault">sf</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">transform_entities</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">trans</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> selection</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">to_a</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> <br /> </span><span class="syntaxcomment">#new_view = view.zoom_extents<br /></span><span class="syntaxdefault"> <br /> end<br />end<br /><br /><br /><br /><br /><br />class Groter<br /> <br /> def initialize</span><span class="syntaxkeyword">()</span><span class="syntaxdefault"> <br /> sf </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">read_default </span><span class="syntaxstring">'liquidsscalefactor'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'value'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'100'</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">to_f<br /> <br /> model </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br /> entities</span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_entities<br /> selection </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">selection<br /> <br /> <br /> <br /> boundbox </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">bounds<br /> center</span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> boundbox</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">center<br /> <br /> <br /> if $booleanhelper_scaleoption </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> 1<br /> <br /> center </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> <br /> <br /> <br /> end<br /><br /> trans </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Transformation</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">scaling</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">center</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> sf</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">transform_entities</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">trans</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> selection</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">to_a</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> <br /> </span><span class="syntaxcomment">#new_view = view.zoom_extents<br /></span><span class="syntaxdefault"> <br /> end<br />end<br /><br /><br /> <br /> <br /> <br /> <br /><br /></span><span class="syntaxcomment">#=============================================================================<br /></span><span class="syntaxkeyword">if(</span><span class="syntaxdefault"> not $booleanhelper_menu_loaded </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> <br /> <br /> add_separator_to_menu</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Plugins"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> new_menu </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Plugins"</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">add_submenu</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Boolean helper"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> new_toolbar </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> UI</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Toolbar</span><span class="syntaxkeyword">.new(</span><span class="syntaxstring">"Boolean helper"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> plugins </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">find_support_file</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Plugins"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> imgdir </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">join</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">plugins</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">"Booleanhelper"</span><span class="syntaxkeyword">)<br /><br /></span><span class="syntaxdefault"> $cmdbooleanhelperscale </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> UI</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Command</span><span class="syntaxkeyword">.new(</span><span class="syntaxstring">"Scale down"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{</span><span class="syntaxdefault">Bhelper</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Kleiner</span><span class="syntaxkeyword">.new()</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault"> $cmdbooleanhelperscale</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">small_icon </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">join</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">imgdir</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">"smaller.png"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> $cmdbooleanhelperscale</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">large_icon </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">join</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">imgdir</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">"smallerL.png"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> <br /> <br /><br /> new_menu</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$cmdbooleanhelperscale</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> new_toolbar</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$cmdbooleanhelperscale</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> <br /> $cmdbooleanhelperscale1</span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> UI</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Command</span><span class="syntaxkeyword">.new(</span><span class="syntaxstring">"Scale up"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{</span><span class="syntaxdefault">Bhelper</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Groter</span><span class="syntaxkeyword">.new()</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault"> $cmdbooleanhelperscale1</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">small_icon </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">join</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">imgdir</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">"bigger.png"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> $cmdbooleanhelperscale1</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">large_icon </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">join</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">imgdir</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">"biggerL.png"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> <br /><br /><br /> new_menu</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$cmdbooleanhelperscale1</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> new_toolbar</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$cmdbooleanhelperscale1</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> <br /> cmd </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> UI</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Command</span><span class="syntaxkeyword">.new(</span><span class="syntaxstring">"set scale factor"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{</span><span class="syntaxdefault">Bhelper</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Getinfo</span><span class="syntaxkeyword">.new()}<br /></span><span class="syntaxdefault"> <br /> new_menu</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">cmd</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> new_toolbar</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">show<br />Bhelper</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Tltip</span><span class="syntaxkeyword">.new()<br /></span><span class="syntaxdefault"> $booleanhelper_menu_loaded </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> true<br />end <br /><br />end </span><span class="syntaxcomment">#module<br /><br /></span><span class="syntaxdefault"> </span>
Is it correct like this??
-
if Sketchup.read_default('liquidsscalefactor','value', '100') == nil Sketchup.write_default('liquidsscalefactor','value',sf) end
Will never==nil
as you tell it to set it to '100' if it is nil in the 'read_default' [the third optional argument].
It's better to use something like my example... where you read its value, and it's set as '100' it it's NOT already set at all, OR it's set to be whatever it's value is already when read; then IF it's not s string it's set to '100' - to rescue us from you having accidentally setting it to something like an Array [100] etc in an earlier version...
Just read through your code and every time you read/write/get/set sf/@@sf etc check it's a string - except when you use it in a calculation - for the Scaling etc - where you use .to_f on it to turn it from a string into a float value - as the scale wants a 'number' - the registry entry and inputbox dialog use a 'string'... -
if Sketchup.read_default('liquidsscalefactor','value', '100') == nil
Little mistake, replaced all the read_default lines in the same way.. (in the editor)
-
hi,
I've been following this topic due to a keen interest in 3d printing, and have wanted to make a suggestion.
I can't find the code I played around with in the past which is the basis of my suggestion,
however Jim mentioned where it comes from in another post today, so I'll simply pass that on...http://code.google.com/apis/sketchup/docs/ourdoc/model.html#add_notethe idea is just write a screen note when working at scale and remove it when back to output scale.
I was looking into actually blocking exporting at scale, but didn't get it working.
I haven't had time yet, but I'll do some Mac tests and let you know if there are any issues.
john
-
@driven said:
hi,
I've been following this topic due to a keen interest in 3d printing, and have wanted to make a suggestion.
I can't find the code I played around with in the past which is the basis of my suggestion,
however Jim mentioned where it comes from in another post today, so I'll simply pass that on...http://code.google.com/apis/sketchup/docs/ourdoc/model.html#add_notethe idea is just write a screen note when working at scale and remove it when back to output scale.
I was looking into actually blocking exporting at scale, but didn't get it working.
I haven't had time yet, but I'll do some Mac tests and let you know if there are any issues.
john
Hi John,
I like your idea's! I know from experience that exporting a model in the wrong scale is a common mistake in 3D printing design... Not a lethal mistake, unless you order the model in the wrong size... Maybe there's something like a Read-only or immune method in Ruby, I will look for that...
Also the idea of model-notes is a good idea. I suggest an 'X' sign for every scale-up action. So when the model is in normal state no X sign is visible. If you've triple-scaled your model there will be three X's in the left top of the screen.
Also the X model-note provides a good feedback on the scale action, so after the scale action the script can do viewZoomExtents without loosing your sense of scale.
I'm also curious how this script behaves on the mac, so let me know.. -
hi,
had a short play last night, everything seems to work as designed... however, an interesting but 'odd' feature was the ability to independently scale anything selected.
I had assumed it would only work on a 'scale all' basis and was checking a not-grouped object when I had only a single line selected.to my surprise it scaled the line and I played around modifying solids for far too long.
I think this ability should be a separate feature or even a second tool.
It could cause huge confusion when preparing models for printing, but is great fun for creating objects.
I would suggest limiting Boolean Helper to 'auto select-all' and scale up/down at the pre-set's.
and then a second plugin 'edge scaler' with a incremental slider at the tool-tip would be great.
just my thoughts
john
-
Hi John,
I see! when scaling up and down a separate line or face you get all kind of weird shapes... really fast
Edge scaler is a great idea! Maybe that will be my next project... thanx for the suggestion.
So the plugin has to select all before scaling. Thats better indeed, I'll fix that.
What do you think about the X message-scale-feedback?
Nice to hear it functions on Mac, too
Liquid
-
liquid,
the "X" factor is good... (but not the TV show)
john
-
You don't need to 'select-all' in the code, just use
model.entities.to_a
as the collection of things to transform in the scale up/down - that way everything gets caught in the scaling up/down changes.A screen-note wouldbe useful to remind you that you have scaled... then the code can erase it when you've scaled down...
-
I like where this is going!
-
@ TIG
yeah, "select all" is user language.
model.entities.to_a
= programmers language -
Working on the feedback of the scale action (X = one time scaled up XX =two times etc.)
I have some variable (array) filled with X characters. Its called$xfeedback
To put it on screen I use:
@xnote = model.add_note $xfeedback.to_s, 0.01, 0.02
.That works. But to update it I would like to delete the screen-note entity before showing it again like this:
model = Sketchup.active_model entities = model.active_entities entities.erase_entities(@xnote) if @xnote
I know to delete something with
erase_entities
it has to be an array. So I tried also this:
entities.erase_entities(@xnote.to_a) if @xnote
but it's not working.
Code structure is like this:
<span class="syntaxdefault"><br />require </span><span class="syntaxstring">'sketchup.rb'<br /><br /></span><span class="syntaxdefault">$xfeedback </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[</span><span class="syntaxstring">"X"</span><span class="syntaxkeyword">,</span><span class="syntaxstring">"X"</span><span class="syntaxkeyword">,</span><span class="syntaxstring">"X"</span><span class="syntaxkeyword">,</span><span class="syntaxstring">"X"</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> </span><span class="syntaxcomment"># Test situation presuming 4 times scaled up.<br /><br /></span><span class="syntaxdefault">module Test<br /><br />class Scaledown<br /> <br /><br />def initialize</span><span class="syntaxkeyword">()</span><span class="syntaxdefault"> <br /> </span><span class="syntaxcomment"># Scaling action<br /></span><span class="syntaxdefault"> <br /> model </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br /> entities </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities<br /> if entities</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">!=</span><span class="syntaxdefault"> nil<br /> <br /> l </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> $xfeedback</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">to_i </span><span class="syntaxkeyword">-</span><span class="syntaxdefault"> 1 <br /> $xfeedback</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">delete_at</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">l</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> <br /> model </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br /> entities </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_entities<br /> entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">erase_entities</span><span class="syntaxkeyword">(@</span><span class="syntaxdefault">xnote</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> if </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">xnote<br /><br /> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">xnote </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_note $xfeedback</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">to_s</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0.01</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0.02<br /><br /><br /><br /> else <br /> nil<br /> end</span><span class="syntaxcomment">#if<br /><br /><br /><br /><br /><br /><br /></span><span class="syntaxdefault">end</span><span class="syntaxcomment">#def<br /></span><span class="syntaxdefault">end</span><span class="syntaxcomment">#class<br /></span><span class="syntaxdefault">end</span><span class="syntaxcomment">#module </span><span class="syntaxdefault"></span>
Please help
-
Shouldn't it be @@xnote ?
Anyway, something like...
entities.erase_entities(@xnote)
should work... or use [@xnote] to make it an array, if it MUST be one (?)...
However, this will work too
@xnote.text='newtext'
to change it ??? -
may not be of any help, but
when you create a screen note SU creates a new Text entity (each time)
"#Sketchup::Text:0x1ef0a000", "#Sketchup::Text:0x1f0131a4", etc...
so I guess if you capture those you can delete them.
john
-
Hello friends,
I made some improvements to the boolean-helper plugin:
- it scales everything in the model
- it gives feedback on the total scale-factor
- it auto zooms to the model-extents.
But I need some help:
When the model is scaled up, feedback is generated in the form of a
sketchup::text
entity. My problem: when the the model is deleted (not select all), the text entity remains on the screen (entities[0]
) while there is no model.So I have to monitor that.
How do I do that??
I came up with this solution:
<span class="syntaxdefault">if entities</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">class </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Text </span><span class="syntaxkeyword">&&</span><span class="syntaxdefault"> entities</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> nil<br /> </span><span class="syntaxkeyword">@@</span><span class="syntaxdefault">xnote </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> entities</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@@</span><span class="syntaxdefault">notetext </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">" "<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@@</span><span class="syntaxdefault">xnote </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_note </span><span class="syntaxkeyword">@@</span><span class="syntaxdefault">notetext</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0.01</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> 0.99</span>
But if I put this code in booleanhelper.rb it only runs when the user invokes it.
While it has to run all the time.I've also read something about
Sketchup::EntityObserver
. Is that relevant in this case???Thnx for your help
Advertisement