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

    Redirect puts to file?

    Scheduled Pinned Locked Moved Developers' Forum
    9 Posts 5 Posters 684 Views 5 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

      Since the ruby console some times stops updating if it's an intensive command, I'd like to output puts statement to a file, instead of the Ruby console. Is that possible?

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

      1 Reply Last reply Reply Quote 0
      • T Offline
        todd burch
        last edited by

        You can put this in your script, but don't leave it there!!

        
        module Kernel 
          alias_method ;real_puts, ;puts 
          def puts(s) ; 
        	real_puts("real puts ; #{s}") ; 
          end 
        end 
        
        puts "Hi there" ;
        
        

        Inside the overridden method, you can do anything you want - write to a file, add a time stamp, create a webdialog and make your own ruby console, whatever you want. I show it to call the real puts method, but that doesn't have to happen.

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

          Thanks Todd! 👍

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

          1 Reply Last reply Reply Quote 0
          • A Offline
            azuby
            last edited by

            Kernel#puts is much more complex. it would be better using the splat operator:

            def puts *arg
              #...
            end
            

            You also could switch $stdout.

            azuby

            *error initus :: Blocks | CurrentDate | d/Code | extensionmanager | FFlipper | HideEdges | MeasuredArea | ModelHistory | PluginsHelp | PronButton | SAWSO | SCP | SU²CATT

            Bad English? PM me, correct me. :smile:**

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

              @azuby said:

              end[/code]You also could switch $stdout.

              ❓

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

              1 Reply Last reply Reply Quote 0
              • A Offline
                azuby
                last edited by

                $stdout points to an IO object. A File object is an IO object too:
                File.ancestors #=> [File, IO, File::Constants, Enumerable, Object, Kernel]

                azuby

                *error initus :: Blocks | CurrentDate | d/Code | extensionmanager | FFlipper | HideEdges | MeasuredArea | ModelHistory | PluginsHelp | PronButton | SAWSO | SCP | SU²CATT

                Bad English? PM me, correct me. :smile:**

                1 Reply Last reply Reply Quote 0
                • TIGT Offline
                  TIG Moderator
                  last edited by

                    file = File.new(ErrorLogFile_Path_Name,"w")
                    file.puts("MyErrorText...")
                  

                  ?

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • Chris FullmerC Offline
                    Chris Fullmer
                    last edited by

                    I just came across this new functionality of SU7 as posted on the API blog back in November:

                    Send ruby console output to the standard out
                    If you start up SketchUp from the command line, you can pipe to standard error and see ruby puts statements appear for you.
                    Sketchup.exe > myRubyLog.txt

                    I have not tried it, but that seems like what you were looking for.

                    Chris

                    Lately you've been tan, suspicious for the winter.
                    All my Plugins I've written

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

                      Interesting. It gives a bunch of error messages from scripts that initializes. But it didn't seem to pipe any errors when I typed in 5 / 0 in the console.

                      When I used one of my plugins that uses the puts method, it didn't update the file automatically, but only when I closed down SU. Not 100% sure how this works. But it sure is useful to catch startup errors. LibFredo got some for instance.

                      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