• Login
sketchucation logo sketchucation
  • Login
🤑 30% Off | Artisan 2 on sale until April 30th Buy Now

Redirect puts to file?

Scheduled Pinned Locked Moved Developers' Forum
9 Posts 5 Posters 684 Views
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.
  • T Offline
    thomthom
    last edited by 2 Feb 2009, 23:57

    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 3 Feb 2009, 01:26

      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
      • T Offline
        thomthom
        last edited by 3 Feb 2009, 08:21

        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 3 Feb 2009, 14:15

          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
          • T Offline
            thomthom
            last edited by 3 Feb 2009, 14:18

            @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 3 Feb 2009, 15:31

              $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
              • T Offline
                TIG Moderator
                last edited by 3 Feb 2009, 15:47

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

                ?

                TIG

                1 Reply Last reply Reply Quote 0
                • C Offline
                  Chris Fullmer
                  last edited by 16 Feb 2009, 06:14

                  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
                  • T Offline
                    thomthom
                    last edited by 16 Feb 2009, 08:29

                    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