sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Undocumented class: Sketchup::Console

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 659 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • thomthomT Offline
      thomthom
      last edited by

      Sketchup::Console
      Instance methods:

      • write Outputs strings to the Ruby Console. Returns the length of the string. (Not newline terminated)

      SKETCHUP_CONSOLE refers to an instance of Sketchup::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 puts or p for debugging purposes and still output things to the console.

      The puts method 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>
      

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        @thomthom said:

        This class can be useful if you want/need to redirect puts or p for debugging purposes and still output things to the console.

        The puts method 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 the puts() method that ALL ruby objects inherit, including IO class and subclass objects, like File class.

        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 the IO class overrides it's inherited puts() 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 of Math::log()

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          It was just a pseudo code of how the puts behave in SU.

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement