[Plugin] Boolean helper update 08122011

[Plugin] Boolean helper update 08122011

Postby liquid98 » Sun Apr 10, 2011 4:37 pm

This is my modest contribution to the community:

Booleanhelper

The Boooleanhelper plug-in lets you quickly scale up and down your model.
This is especially useful for those people who use Sketchup for 3d printing.
Performing boolean operations or lathe operations on small models (mm size) is problematic in Sketchup, because Sketchup doesn't handle small faces very well.
By scaling up the model these problems disappear. After all operations are done
you can scale down your model to its original dimensions.
Also useful to close small holes in your model.

Your opinions and suggestions are welcome!

Features:

- Visual feedback on scale-factor.
- Scale down at once.
- It is possible to save your work, and scale down later. (feedback not yet provided)
- Auto zoom extents.

Installation:
Open the zipfile and copy booleanhelper.rb and the folder called Booleanhelper into the SU plugins directory.

Have fun!!


If you have problems with unsolicited messageboxes, please download the latest version below:
0
Last edited by liquid98 on Thu Aug 25, 2011 12:12 am, edited 13 times in total.
Things that flourish fall into decay. This is not-Tao, And what is not-Tao soon ends ~ Lao tse
User avatar
liquid98 
 

Re: [Plugin] Boolean helper

Postby dedmin » Sun Apr 10, 2011 4:58 pm

Thanks,
Nice idea!
Some suggestions - add option to scale the whole scene and to zoom extents after each scale.
0

dedmin 
 

Re: [Plugin] Boolean helper

Postby Dave R » Sun Apr 10, 2011 5:23 pm

Interesting. How does this differ from using the Scale tool or the Tape Measure tool to resize the model or a component/group?
0
%

(THERE'S NO PLACE LIKE)

G28 X0.0 Y0.0 Z0.0

M30

%
User avatar
Dave R 
Global Moderator
 

Re: [Plugin] Boolean helper

Postby liquid98 » Sun Apr 10, 2011 5:39 pm

Dave R wrote:Interesting. How does this differ from using the Scale tool or the Tape Measure tool to resize the model or a component/group?


Well this goes faster, and you don't have to remember the scale factor.
The difference is that you don't have to select a grip point on the scaling-box,
enter a value and press enter. And the other way round..
If you have to that 20 times a day, you'll look for something faster!
0
Things that flourish fall into decay. This is not-Tao, And what is not-Tao soon ends ~ Lao tse
User avatar
liquid98 
 

Re: [Plugin] Boolean helper

Postby Dave R » Sun Apr 10, 2011 5:56 pm

I see. Cool.

I usually use the Tape Measure tool but maybe I'll give this a try. Thanks.
0
%

(THERE'S NO PLACE LIKE)

G28 X0.0 Y0.0 Z0.0

M30

%
User avatar
Dave R 
Global Moderator
 

Re: [Plugin] Boolean helper

Postby Ken » Sun Apr 10, 2011 9:25 pm

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
0
Fight like your the third monkey on Noah's Ark gangway.
User avatar
Ken 
Premium Member
Premium Member
 

Re: [Plugin] Boolean helper

Postby Dave R » Sun Apr 10, 2011 9:50 pm

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.
0
%

(THERE'S NO PLACE LIKE)

G28 X0.0 Y0.0 Z0.0

M30

%
User avatar
Dave R 
Global Moderator
 

Re: [Plugin] Boolean helper

Postby Humpmetwice » Sun Apr 10, 2011 10:31 pm

Dave R wrote: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!
0
User avatar
Humpmetwice 
 

Re: [Plugin] Boolean helper

Postby Dave R » Sun Apr 10, 2011 10:44 pm

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.
0
%

(THERE'S NO PLACE LIKE)

G28 X0.0 Y0.0 Z0.0

M30

%
User avatar
Dave R 
Global Moderator
 

Re: [Plugin] Boolean helper

Postby liquid98 » Mon Apr 11, 2011 2:35 pm

Ken wrote: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.
0
Things that flourish fall into decay. This is not-Tao, And what is not-Tao soon ends ~ Lao tse
User avatar
liquid98 
 

Re: [Plugin] Boolean helper

Postby liquid98 » Mon Apr 11, 2011 2:41 pm

dedmin wrote: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.
0
Things that flourish fall into decay. This is not-Tao, And what is not-Tao soon ends ~ Lao tse
User avatar
liquid98 
 

Re: [Plugin] Boolean helper

Postby liquid98 » Mon Apr 11, 2011 2:41 pm

Ken wrote: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
0
Things that flourish fall into decay. This is not-Tao, And what is not-Tao soon ends ~ Lao tse
User avatar
liquid98 
 

Re: [Plugin] Boolean helper

Postby TIG » Mon Apr 11, 2011 2:51 pm

Liquid98
Using
Geom::Transformation.scaling nnnnn
scales everything by nnnnn, 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)
:geek:
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Boolean helper

Postby liquid98 » Mon Apr 11, 2011 4:37 pm

TIG wrote:Liquid98
Using
Geom::Transformation.scaling nnnnn
scales everything by nnnnn, 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)
:geek:



TIG, thanks for the suggestions, I am fully aware of the fact that
Geom::Transformation.scaling(ORIGIN, nnnnn) will scale
scale everything by nnnnn. With nnnnn 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.
0
Things that flourish fall into decay. This is not-Tao, And what is not-Tao soon ends ~ Lao tse
User avatar
liquid98 
 

Re: [Plugin] Boolean helper

Postby TIG » Mon Apr 11, 2011 4:50 pm

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') and Sketchup.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...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Boolean helper

Postby liquid98 » Wed Apr 13, 2011 6:19 pm

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 classes Kleiner
and Groter, 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 in Getinfo 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!
0
Things that flourish fall into decay. This is not-Tao, And what is not-Tao soon ends ~ Lao tse
User avatar
liquid98 
 

Re: [Plugin] Boolean helper

Postby TIG » Wed Apr 13, 2011 6:53 pm

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 :roll:
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Boolean helper

Postby liquid98 » Thu Apr 14, 2011 10:19 pm

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!
0
Things that flourish fall into decay. This is not-Tao, And what is not-Tao soon ends ~ Lao tse
User avatar
liquid98 
 

Re: [Plugin] Boolean helper

Postby TIG » Thu Apr 14, 2011 10:29 pm

'results' IS returned as an array - that's why :roll:
you can get the contents of an array in several ways
array=[0,1,2,3]
a,b,c,d = array
a
>>> 0
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......
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Boolean helper

Postby liquid98 » Fri Apr 15, 2011 7:17 pm

Hi TIG!

I learned a lot today; and

I got it all working!!!! :ecstatic:

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 why sftt 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}")
0
Things that flourish fall into decay. This is not-Tao, And what is not-Tao soon ends ~ Lao tse
User avatar
liquid98 
 

Re: [Plugin] Boolean helper

Postby TIG » Fri Apr 15, 2011 8:47 pm

Little more elegant way...
I would add the optional third part to the read_default as '0'
Then sff=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...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Boolean helper

Postby liquid98 » Fri Apr 15, 2011 9:17 pm

Hi TIG,

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:

Code: Select all
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 :D
0
Things that flourish fall into decay. This is not-Tao, And what is not-Tao soon ends ~ Lao tse
User avatar
liquid98 
 

Re: [Plugin] Boolean helper

Postby TIG » Fri Apr 15, 2011 10:49 pm

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'.
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Boolean helper

Postby liquid98 » Sat Apr 16, 2011 11:19 pm

TIG wrote: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!
0
Things that flourish fall into decay. This is not-Tao, And what is not-Tao soon ends ~ Lao tse
User avatar
liquid98 
 

Re: [Plugin] Boolean helper

Postby TIG » Sun Apr 17, 2011 1:33 pm

Should NOT need the [] - the returned value should be a string '' :?
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Boolean helper

Postby Ken » Sun Apr 17, 2011 1:45 pm

Downloaded the latest version. Here what is happening.

1. If you don't put a value to the scale, the model disappears.

2. The model does not stay at it's present locations like the previous version did.

Ken
0
Fight like your the third monkey on Noah's Ark gangway.
User avatar
Ken 
Premium Member
Premium Member
 

Re: [Plugin] Boolean helper

Postby TIG » Sun Apr 17, 2011 1:59 pm

The scale should default to 1000 if it's not set, or to another value if it has been set before...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Boolean helper

Postby liquid98 » Mon Apr 18, 2011 2:33 pm

Hi Ken, you were right! Thanx for the feedback :P

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
0
Things that flourish fall into decay. This is not-Tao, And what is not-Tao soon ends ~ Lao tse
User avatar
liquid98 
 

Re: [Plugin] Boolean helper

Postby liquid98 » Mon Apr 18, 2011 2:53 pm

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:

Code: Select all
@@x = 1,90
If x contains  ','
do something
?

Thank you :D
0
Things that flourish fall into decay. This is not-Tao, And what is not-Tao soon ends ~ Lao tse
User avatar
liquid98 
 

Re: [Plugin] Boolean helper

Postby TIG » Mon Apr 18, 2011 3:28 pm

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
0
TIG
User avatar
TIG 
Global Moderator
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 

Next


 

Return to Plugins

Who is online

Users browsing this forum: No registered users and 28 guests

Visit our sponsors: