[Plugin] Boolean helper update 08122011
-
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
-
Well, for those who work in Imperial units==inches, it would be cool if you could set the scale factor to overcome the small faces problem but type in the VCB the same numbers as you would if you had not scaled it. Basically, to do away with a bunch of mental math for every value. When finished, reset the scale factor to 1. There's a flaw here somewhere??
-
@mitcorb said:
Well, for those who work in Imperial units==inches, it would be cool if you could set the scale factor to overcome the small faces problem but type in the VCB the same numbers as you would if you had not scaled it.
Hi mitcorb,
That's a nice idea, but I have no clue to achieve it..
Indeed, the script I'm working on scales up as much as you want and than scales everything down to scalefactor 1.
In scaled up state there's a screen-note reference to the actual scale-factor. -
Liquid98
About the screen-text...
Do you mean that it disappears if there is suddenly no other model geometry ?
As soon as any new geometry is added it should reappear ??
I don't see the problem ? On the rare occasions when the user has deleted the entire model [and why would they do that?] the scaling becomes irrelevant anyway, so they can just delete it ?To spot if the only thing left is your screen-text and then erase with an observer to watch for this use
class OnlyScreenTextLeftEntitiesObserver < Sketchup;;EntitiesObserver def onEraseEntities(entities) return if entities[1] entities[0].erase! if entities[0].class==Sketchup;;Text and entities[0].text==$xfeedback.to_s ###?? end end # Attach the observer - do this once at startup Sketchup.active_model.entities.add_observer(OnlyScreenTextLeftEntitiesObserver.new)
-
Hi TIG,
@tig said:
I don't see the problem ? On the rare occasions when the user has deleted the entire model [and why would they do that?] the scaling becomes irrelevant anyway, so they can just delete it ?
I admit, that situation won't occur very often. But I only want to tackle it to learn new stuff...
When I put your code in a .rb file, like this:
<span class="syntaxdefault"> require </span><span class="syntaxstring">'sketchup.rb'<br /><br /></span><span class="syntaxdefault"> class OnlyScreenTextLeftEntitiesObserver </span><span class="syntaxkeyword"><</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">EntitiesObserver<br /> def onEraseEntities</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">messagebox </span><span class="syntaxstring">"OK"<br /></span><span class="syntaxdefault"> end<br /> end<br /> <br /> <br /> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_observer</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">OnlyScreenTextLeftEntitiesObserver</span><span class="syntaxkeyword">.new)</span><span class="syntaxdefault"> </span>
and then start sketchup, create some entities and delete them,
Nothing happens... Why??
-
Well if it did work every time you erased something you'd get the messagebox...
The EntitesObserver is known to be buggy... if we did get it to work and erased an entity within it it'd probably crash anyway - so my snippet probably wasn't the best idea
How about using a selectionObserver...onBulkChange() - you select the things and then erase them and the selection changes... and then looking at model.entities if no [1] and [0] meets test erase it ...
http://code.google.com/apis/sketchup/docs/ourdoc/selectionobserver.html -
I updated the booleanhelper plugin! Please see the first post of this topic.
Advertisement