[Plugin] Boolean helper update 08122011
-
For a @@ variable to be accessible it has to be within the same 'class' - you have set three separate classes so @@ won't work between them - you need a $ global version...
Because it's a global variable I suggested a 'long name' that's highly likely to be used by anyone else and cause unexpected conflicts...
To make a variable that's remembered during that Sketchup session across the classes, you set it in the module using the '$' type... E.G.
$liquidsscalefactor=1000.0
written within the 'module' BUT outside the class/def's, I.E. as you have done, BUT you need to remove the '#'
Note also how I've set it as a 'float' rather than an 'integer' by adding '.0' to the end - it's safer when doing division etc as 1/100 >>> 0 but 1/100.0 >>> 0.01
This sets the value of the scaling for that Sketchup session and it is remembered across uses of the three tools.
You then need to change the dialog part to [re]set it thus...
values = [$liquidsscalefactor]
and then later...
$liquidsscalefactor, = results
OR alternatively you could write it as...
$liquidsscalefactor = results[0]
Whenever you open Sketchup it starts at 1000, but any new value is remembered thereafter.
The 1000 value is reverted after a close and reopen of Sketchup.
You CAN save the value permanently so that it is always remembered between sessions using Sketchup.write_default/read_default etc... but that's for another day once you get this method working -
Hi TIG,
implemented the global variable, works great!
I see: the @@variable is only valid within a class right?
Questions
Is results[0] an element of an array? Are all these results of the inputbox stored during the session?
$booleanhelperscalefactor, = results
, if I omit the,
$booleanhelperscalefactor
becomes an array, why?To give extra info about the scale-factor I adapted the code like this:
cmd = UI::Command.new("Scale factor "+$booleanhelperscalefactor.to_s) {Bhelper::Groter.new() } cmd.small_icon = File.join(imgdir, "bigger.png") cmd.large_icon = File.join(imgdir, "biggerL.png") cmd.tooltip = ("Scale factor "+$booleanhelperscalefactor.to_s) cmd.menu_text = ("Scale factor "+$booleanhelperscalefactor.to_s)
The text sticks to the initial value of
$booleanhelperscalefactor
, when i change the scalefactor in sketchup the tooltip and menu-tekst won't change.Thnx for your help.
By the way, I found the Automatic_SketchUp pdf document, a good resource!
-
'results' IS returned as an array - that's why
you can get the contents of an array in several ways
array=[0,1,2,3]
a,b,c,d = array
a0
b
1
etc
OR as
a=array[0]
a
0
IF you have a ONE element array like yours
xxx = results[0]
is exactly the same as
xxx, = results
as xxx is set the the first [0] element in both cases...The cmd tooltip is set at the moment the the cmd is defined - so it shows the then current scalefactor.
When you change the scale factor you don't change the then defined details.
You COULD set the cmd as a $ variable so you know its 'handle' - use an unusual reference - say $cmdbooleanhelperscalefactor - When you change the scalefactor in the dialog also add a lie saying
$cmdbooleanhelperscalefactor.tooltip = ("Scale factor "+$booleanhelperscalefactor.to_s)
Not sure it'll work BUT you can see how it might be construed...... -
Hi TIG!
I learned a lot today; and
I got it all working!!!!
Thanx a lot for your help!
I have two final questions though:
(1)
sfa = Sketchup.read_default('liquidsscalefactor','value') sff = sfa[0].to_f . . . trans = Geom::Transformation.scaling(ORIGIN, 1.0/sff)
Is there a more elegant solution to convert sfa to a floating value?
(2)
And I don't understand whysftt
is not updating when the scalefactor (sfa) is set??
sfa = Sketchup.read_default('liquidsscalefactor','value') sftt = sfa[0].to_f . . . cmd.menu_text = ("Scale down with factor #{sftt}")
-
Little more elegant way...
I would add the optional third part to theread_default
as'0'
Thensff=1000.0 if sff==0.0
I don't see any 'write_default
' code ?
When the dialog changes the sf value the 'liquidsscalefactor
' needs to be [re]written... -
Hi TIG,
@unknownuser said:
I don't see any 'write_default' code ?
My complete code is now attached in the rb-file below....
Am I right? It has to be:
sfa = Sketchup.read_default('liquidsscalefactor','value', 0) sff = sfa[0].to_f
Instead of that I was looking for a more elegant solution like:
sfa = Sketchup.read_default('liquidsscalefactor','value', 0).to_f
but that's not possible?
TIG, Thnx for your help once again, I lost count already
-
Your
sfa = Sketchup.read_default('liquidsscalefactor', 'value', 0).to_f
will work without intermediate steps... although I'd set the fall-back option to '0'. -
@tig said:
Your
sfa = Sketchup.read_default('liquidsscalefactor', 'value', 0).to_f
will work without intermediate steps... although I'd set the fall-back option to '0'.I got it working like this:
sf = (Sketchup.read_default 'liquidsscalefactor', 'value', '0')[0].to_f
final code in first post. Thnx!
-
Should NOT need the [] - the returned value should be a string ''
-
Downloaded the latest version. Here what is happening.
-
If you don't put a value to the scale, the model disappears.
-
The model does not stay at it's present locations like the previous version did.
Ken
-
-
The scale should default to 1000 if it's not set, or to another value if it has been set before...
-
Hi Ken, you were right! Thanx for the feedback
Solved both problems,
It's only possible to enter a number > 0
You now can choose between scale about origin or scale about object's center.
The default is to scale about the object's center. If you want to change that, open the ruby-file and uncomment
(remove the #) the first line of code. Please reboot ruby to make it work.Latest version in topic-start
-
Hi TIG,
Would you be so kind to inspect my code briefly to see if there are things that could be done in a better way or are
actually wrong but function by accident?? (code in first topic)And a question
The script accepts only input if its a number > 0 It accepts for instance numbers like 1.90.
But it also accepts numbers like 1,90. Nothing happens then when you
try to use it.
How can I filter this kind of input?I other words, how do I program this:
@@x = 1,90 If x contains ',' do something
?
Thank you
-
Try these tweaks
module Bhelper sf = **'1000.0'**
To make it a 'string'.
Then
@@sf = Sketchup.read_default('liquidsscalefactor','value'**,'1000.0'**)**.to_f**
to trap for it not having set [should never happen!] and.to_f
to turn the read string into a 'float'.
You don't need
@@sf = results.to_s.to_f
as it's now already a float, and should be got thus from the input@@sf=results[0]
@@sf = results
is wrong/duplicated AND also
Sketchup.write_default('liquidsscalefactor','value',@@sf**.to_s**)
should be inside the 'begin' section, otherwise it 'fires' even after an error.In your two similar classes
def initialize() sf = (Sketchup.read_default 'liquidsscalefactor', 'value', '0')[0].to_f
should both become
def initialize() sf = (Sketchup.read_default 'liquidsscalefactor', 'value', '1000.0')**.to_f**
-
Well I tried again. This time I get the error code "NilClass"
Ken
-
Ken
Please bear with him...
This is his first Ruby and whilst it is a good idea it needs some 'fine tuning' -
@tig said:
Ken
Please bear with him...
This is his first Ruby and whilst it is a good idea it needs some 'fine tuning'Hello TIG
I was, I waited and no one else seemed to have this problem. I am not in a hurry just trying to get to him info. He is a lot further along in Ruby than I am.
Ken
-
HI Ken and TIG,
Thanx for your feedback, I really enjoy learning to code with your help!
I decided to change the approach of Booleanhelper a bit. In the latest version (1.04) its only possible to scale with factor 10, 100, or 1000. You can choose a value from a dropdown-menu.
I've done this because the plugin is only needed to temporary scale up and down a model.
If you work on a scaled up model for instance with scale 100 you can adapt your measurements easily.
In other words, it makes no sense to scale up and down with a factor of eg 9,81.@TIG Here is the code of version 1.04. I managed to integrate the scalefactor in the tooltip of the toolbar icons, but the method I used for the tooltips is not working for the menu-items, unfortunately.
Further I put this piece of code in the Getinfo class. As a result the tooltips only update after setting the scalefactor. My idea was to put the code for the tooltip outside the classes, but to no avail;<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 /><br /><br />module Bhelper<br /><br /> sf </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> 100<br /> 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 /> <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">)<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">]<br /></span><span class="syntaxdefault"> <br /> <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#{@@sf}"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> <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#{@@sf}"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> <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 /> <br /> <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 /><br /></span><span class="syntaxdefault"> <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 /><br /> $booleanhelper_menu_loaded </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> true<br />end <br /><br />end </span><span class="syntaxcomment">#module </span><span class="syntaxdefault"></span>
-
Your
$cmdbooleanhelperscale.tooltip = ("Scalefactor#{@@sf}")
does work IF you change the scale-factor... so set it to work at initialization...
To get the tooltips working from initialization you must set the tooltip in each of the buttons' initialization code; after the @@sf has be established.
Incidentally this is a clever way of having a changing tooltip... where bit you glean it from? Or was it of your own devising??A few more observations - some very minor:-
For
$cmdbooleanhelperscale1
a 1.0/ version -$cmdbooleanhelperscale1.tooltip = "Scalefactor #{1.0/@@sf}"
as it'd make it clearer which is increasing and which is decreasing.Set
$cmdbooleanhelperscale.tooltip = ("Scalefactor#{@@sf}")
with a space between the text and 'number' like "Scalefactor #{@@sf}".Wouldn't it be good to re-zoom after you scale stuff? To do this add
Sketchup.send_action("viewZoomExtents:")
to your methods, immediately after the scaling has been done.'Capitalize' or 'Title-Case' the menu item text where you set the scale factor.
-
Hi TIG, thanx again for your suggestions.
What do you exactly mean by initialization?
@unknownuser said:... so set it to work at initialization...
To me its seems logical to put
@@sf = (Sketchup.read_default 'liquidsscalefactor', 'value', '100').to_s $cmdbooleanhelperscale.tooltip = ("Scalefactor #{@@sf}") $cmdbooleanhelperscale1.tooltip = ("Scalefactor #{@@sf}") $cmdbooleanhelperscale.menu_text = ("Scalefactor #{@@sf}") $cmdbooleanhelperscale1.menu_text = ("Scalefactor #{@@sf}")
in the beginning of the script. Tried that, but it doesn't work. Sketchup gives this error:
undefined method `tooltip=' for nil:NilClassWhen I place the tooltip and menu_text lines in the Getinfo class, the tooltip works but the menu-text falls back on the name in
$cmdbooleanhelperscale = UI::Command.new("Scale down") {Bhelper::Kleiner.new() }
in this case 'Scale down'.Furter,
$cmdbooleanhelperscale1.tooltip = "Scalefactor #{1.0/@@sf}
does not work.......??After some trial and error I eventually found out about how to put a variable in a tooltip.
I already had your suggestion about the tooltip, later I found out how to combine text and variables in
a messagebox. Just combined two pieces of existing information...About the re-zoom, I tried that. But in the case of rezoom there's no feedback on the scale-action.
You just see the same shape as before. A message-box wouldn't work that good, because you have to
click it away, it interrupts the flow of use.First post: plugin + toolbar images
Advertisement