Undocumented class: Sketchup::Console
-
Sketchup::Console
Instance methods:writeOutputs strings to the Ruby Console. Returns the length of the string. (Not newline terminated)
SKETCHUP_CONSOLErefers to an instance ofSketchup::Console.
Though you can make your own instance, it doesn't appear to make a difference.This class can be useful if you want/need to redirect
putsorpfor debugging purposes and still output things to the console.The
putsmethod reversed engineered:<span class="syntaxdefault">def puts</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">value</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> SKETCHUP_CONSOLE</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">write</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"#{value}\n"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> nil<br />end<br /></span> -
@thomthom said:
This class can be useful if you want/need to redirect
putsorpfor debugging purposes and still output things to the console.The
putsmethod reversed engineered:<span class="syntaxdefault">def puts</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">value</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> SKETCHUP_CONSOLE</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">write</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"#{value}\n"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> nil<br />end<br /></span>Careful!
If a user does that at the console (in
Object,) they override theputs()method that ALL ruby objects inherit, includingIOclass and subclass objects, likeFileclass.Strange things might happen. You may wish to use a file instance's
puts()method to write to the file, and not want it echoing to the console. (If theIOclass overrides it's inheritedputs()method, we may not have a problem.)If you must override
puts()then ONLY do it in your custom module or class.I find it is safer (and more robust,) to use a custom
echo()method, which can send to$stdout(which goes to the console anyway,) and / or send to a log file, or neither of them depending on a couple of boolean constants.<span class="syntaxdefault">def echo</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">value</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> puts</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">value</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> if ECHO<br /> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">logfile</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">puts</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">value</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> if LOGGING<br /> nil<br />end<br /></span>P.S. I don't call it
log()because ofMath::log() -
It was just a pseudo code of how the puts behave in SU.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register LoginAdvertisement