[Plugin] Boolean helper update 08122011
-
@dave r said:
Since I only work with components, I leverage the fact that working on a scaled up copy of the component edits the correctly sized copies too. When I need to do something that might generate the tiny faces SketchUp doesn't like, I make a copy of the component, Scale it up with the Scale tool or the Tape Measure, do my work on it and, when the editing has been completed, I close the large version of the component and delete it. No need to scale back down nor worry about where it'll end up when it is scaled back down. I never have to put components back that way because they've never been removed. It works well for things that need to be edited but don't require scaling, too. I happen to be working on one right now as a matter of fact. Of course this method doesn't help those who prefer to make groups instead. This plugin could be handy for them.
Learn something new here everyday, thats cool Dave because I didn't know you could do that. I thought if you copied the component and scaled it the other one would scale as well. To be honest I don't think I've ever tried it because of thinking that way but knowing this now it will save alot of time. Thanks!
-
If you open the component before scaling, you'll scale all of them. If you don't open it, you only scale the one you're working on.
-
@unknownuser said:
Well I like this plugin because I do scale up and down. However, I think 1000 is a little to much for me, so I set it to 10. 3 10's and you are at 1000. However, I did note that the scaling moves the center of the selection. It would be nice if the scaling kept the selection centered at the same location.
So thanks for the plugin.
Ken
Hi ken,
I see what you mean, I have to do some more research on ruby to fix the center problem.
User input for scale-factor: same thing. -
@dedmin said:
Thanks,
Nice idea!
Some suggestions - add option to scale the whole scene and to zoom extents after each scale.Hi dedmin,
I tested the script with auto zoom extents after scale, but the problem is that there
is no visual-feedback on the scaling action, you just see the same scaled object. -
@unknownuser said:
Well I like this plugin because I do scale up and down. However, I think 1000 is a little to much for me, so I set it to 10. 3 10's and you are at 1000. However, I did note that the scaling moves the center of the selection. It would be nice if the scaling kept the selection centered at the same location.
So thanks for the plugin.
Ken
Hi ken,
I see what you mean, I have to do some more research on ruby to fix the center problem.
User input for scale-factor: same thing.[/quote]Thanx for your input
-
Liquid98
Using
Geom::Transformation.scaling nnnnn
scales everything bynnnnn
, probably using its 'bounds.min'
To do the scaling about the ORIGIN - which won't vary and therefore won't move stuff unexpectedly you should use
Geom::Transformation.scaling(ORIGIN, nnnnn)
-
@tig said:
Liquid98
Using
Geom::Transformation.scaling nnnnn
scales everything bynnnnn
, probably using its 'bounds.min'
To do the scaling about the ORIGIN - which won't vary and therefore won't move stuff unexpectedly you should use
Geom::Transformation.scaling(ORIGIN, nnnnn)
TIG, thanks for the suggestions, I am fully aware of the fact that
Geom::Transformation.scaling(ORIGIN, nnnnn)
will scale
scale everything bynnnnn
. Withnnnnn
as a variable.But the problem is that i like 1000 while other people prefer 10, and I don't want to
work with a dialog box for user input because than you have to make that choice every time
you use script.
So the best case would be that the user sets the scale factor to what he likes and than the script has to remember the scale factor after sketchup is shut down. -
The reason I used 'nnnnn' wasn't because I was suggesting you used a variable... I was showing how to 'anchor' your scaling to the ORIGIN... and because two versions of the scaling transformation are used I didn't want to illustrate one of them in preference to the other!
What you could do is set a 'global value' [$] outside of the script code parts, at the beginning; then users can easily find and edit that one part in the script if they want say x 100 instead of 1000
e.g.$liquidsscalefactor=1000
Then in your 'scale up' part you have
Geom::Transformation.scaling(ORIGIN, $liquidsscalefactor)
and in your 'scale down' part you have
Geom::Transformation.scaling(ORIGIN, 1.0/$liquidsscalefactor)
note the 1.0 to force a float if the $ value is an integer
You could change the menus too...
e.g.UI::Command.new("Scale factor "+$liquidsscalefactor.to_s){Bhelper::Groter.new()}
to show the current value set...An alternative to the global $ variable is to use
Sketchup.read_default('liquidsscalefactor','value')
andSketchup.write_default('liquidsscalefactor','value',nnnnn)
to get/set a value with Sketchup that is always used - here replaced by 'nnnnn' in the 'write' part.
You have a test that says if it's not set [first run] it's 'written' to be '1000'.
Else it's set to what is 'read'; with.to_f
to convert it from a string to a float value.
You also add an extra item to your menu 'Set scale factor' - this opens a simple dialog and lets the user enter a value like '100' [as a string] - it's written to Sketchup as shown above and re-read back [with .to_f] when you use either of the other two options, to scale up/down... The value that we get from Sketchup.read_default() is remembered across sessions and common in all SKPs until the user resets its value... -
Hi TIG, I did some experiments today,
I understand what you mean about the transformation. Using 1.0/nnnn and nnnn is just more convenient..
Setting a global variable was easy. And worked right away. But I also read some wiki that said : "avoid global variables!! ". Is that why you give it ($liquidsscalefactor)such a long name?
Getting a variable from input: also easy.
But to get my variable
lsf
in to the two classesKleiner
andGroter
, is something I don't understand.
My input method is like this:` class Getinfo
def initialize() prompts = ["Enter scalefactor "] values = [1000] results = UI.inputbox prompts, values, "Scalefactor." return if not results @lsf, = results UI.messagebox @lsf.class
end
end`
@lsf
inGetinfo
is a Fixnum class, is that alright?
But in my two classes@lsf
is NilClass (empty)I tried also
$lsf
and@@lsf
.Any help???
I attached the file I'm working on..
PS:TIG, Realy cool you put all that effort in helping people with ruby and Sketchup! I'm sure lots of people can learn from your posts!
-
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...
Advertisement