• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

Clear the Ruby Console with Win32 API?

Scheduled Pinned Locked Moved Developers' Forum
15 Posts 9 Posters 14.0k Views 9 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.
  • T Offline
    thomthom
    last edited by 24 Feb 2010, 18:36

    Using WinDowse I could change the Ruby Console text output.

    So I was wondering - one should be able to do that using Win32 API calls.
    But I'm not so experienced with the Win32 API.

    How would you:
    Get the active Ruby Console window?
    I guess one can make the command work only from the console. So the method would get the handle for the currently active foreground window and check that it's title is "Ruby Console".
    ?

    How do you get the handles for the correct textbox?

    How do you change its text properties.

    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
      tbd
      last edited by 24 Feb 2010, 20:12

      last time when I checked it didn't help much because the whole text will be back on the print/puts

      SketchUp Ruby Consultant | Podium 1.x developer
      http://plugins.ro

      1 Reply Last reply Reply Quote 0
      • C Offline
        Chris Fullmer
        last edited by 24 Feb 2010, 20:33

        Have you looked at Jim's plugin that doe this? I don't know about the prints/puts thing though. His plugin only works in 32bit, so it never quite worked for me. 😞

        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 24 Feb 2010, 20:45

          @unknownuser said:

          last time when I checked it didn't help much because the whole text will be back on the print/puts

          awh crud! why on earth?!?

          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
            thomthom
            last edited by 25 Feb 2010, 07:38

            So this means SU caches ALL the text? it doesn't append to the existing text, to completely rewrites it?? No wonder that thing is slow!

            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
              thomthom
              last edited by 25 Feb 2010, 20:45

              looking at this again:

              After using WinDowse to clear the text:

              • if I click the command line textbox in the Ruby Console to bring up any old commands - then all the old stuff comes back
              • if I don't do that - and use a script that uses a puts statement - or type in a new command or blank line into the Ruby Console command line - then the old history doesn't come back any more.

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

              1 Reply Last reply Reply Quote 0
              • J Offline
                jessejames
                last edited by 25 Feb 2010, 22:16

                @thomthom said:

                So this means SU caches ALL the text? it doesn't append to the existing text, to completely rewrites it?? No wonder that thing is slow!

                The Ruby console "As Is" needs to die a torturous and horrible death, and in its place, a new multi-line console "shining prince" (not IO! 😉 ) would herald in the new era of scripting bliss!

                Always sleep with a loaded gun under your pillow!

                1 Reply Last reply Reply Quote 0
                • T Offline
                  TIG Moderator
                  last edited by 26 Feb 2010, 09:15

                  @thomthom said:

                  looking at this again:
                  After using WinDowse to clear the text:

                  • if I click the command line textbox in the Ruby Console to bring up any old commands - then all the old stuff comes back
                  • if I don't do that - and use a script that uses a puts statement - or type in a new command or blank line into the Ruby Console command line - then the old history doesn't come back any more.

                  After you have cleared the console why not have your code do an empty puts to help you ?

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    thomthom
                    last edited by 26 Feb 2010, 09:23

                    well - I have not written the code yet. I've only used WinDowse to poke about.
                    But yes - that would be a solution - if I now could work out how to do this from Ruby.

                    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
                      TIG Moderator
                      last edited by 26 Feb 2010, 09:45

                      I have PM'd you clearConsole.rb that works OK - I didn't publish it here as I'm unsure where it came from - no accreditation in the header ?
                      ❓

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        thomthom
                        last edited by 26 Feb 2010, 11:04

                        Excellent TIG. 👍

                        Now - if only we found the author so we could get this posted publicly...

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

                        1 Reply Last reply Reply Quote 0
                        • J Offline
                          Jim
                          last edited by 26 Feb 2010, 14:57

                          morisdov compiled a small windows exe to clear the console. It is called using the system command. I use it, and like to have it around because I can also double-click it from my file manager and clear the console.

                          http://morisdov.googlepages.com/

                          (I was sure this was posted at morsidov's site, but it does not seem to be available now.)

                          Hi

                          1 Reply Last reply Reply Quote 0
                          • Al HartA Offline
                            Al Hart
                            last edited by 26 Feb 2010, 18:58

                            Here is a routine which should work.

                            If you have problems, let me know.
                            (Sometimes code I extract from larger projects only works because of other plugins I have loaded already)

                            • Place Win32API.so in the Plugins folder (I grabbed a copy from the ruby install and placed it there)
                            • place clear_ruby_console.rb in your Plugins folder.
                            • "Clear Ruby Console" should appear at the bottom of the Window drop-down menu after you start SketchUp

                            clear_ruby_console.rb

                            clear_ruby_console.rb

                            
                            # you need Win32API.so in the Plugins folder for this to work.
                            # I grabbed a copy from the ruby install and placed it there
                            require 'Win32API' 
                            
                            
                            
                            def clear_ruby_console
                            
                            	# Find a window called Ruby Console
                            	# (Note; if there is more than one, then this may not work)
                            	fw = Win32API.new("user32.dll", "FindWindow", ['P', 'P'], 'N')
                            	pw=fw.call(0, "Ruby Console")	
                            	if (!pw)
                            		puts "Ruby Console not found"
                            		return
                            	end#if
                            	
                            	# get the text output window in the Ruby Console
                            	fw_ex = Win32API.new("user32.dll", "FindWindowEx", ['N', 'N', 'P', 'P'], 'N')
                            	h_text = fw_ex.call(pw, 0, "Edit", 0) # Text Input for Ruby Console
                            	if (!h_text)
                            		puts "Ruby Console text window not found"
                            		return
                            	end#if
                            	
                            	# get the output window
                            	h_output = fw_ex.call(pw, h_text, "Edit", 0) # Output for Ruby Console
                            	if (!h_output)
                            		puts "Ruby Console output window not found"
                            		return
                            	end#if
                            	
                            	# Clear the text in the ruby output
                            	# by sending it an empty string
                            	sm = Win32API.new("user32.dll", "SendMessage", ['N', 'N', 'N', 'P'], 'N')	
                            	wm_settext = 0x000c # windows constant to set text
                            	sm.call(h_output, wm_settext, 0, "")	
                            	
                            	#You can change this to whatever message you want to display
                            	#after the console is cleared.
                            	puts "--- Ruby Console Cleared ---"
                            			
                            end#def
                            
                            # Add to Windows menu
                            if ( !$clear_console_loaded)
                               UI.menu("Window").add_item("Create Ruby Console") {clear_ruby_console}
                               $clear_console_loaded = true
                            end
                            
                            
                            
                            

                            Al Hart

                            http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
                            IRender nXt from Render Plus

                            1 Reply Last reply Reply Quote 0
                            • F Offline
                              filsaz
                              last edited by 10 Jun 2010, 21:57

                              @al hart said:

                              Here is a routine which should work.

                              If you have problems, let me know.
                              (Sometimes code I extract from larger projects only works because of other plugins I have loaded already)

                              • Place Win32API.so in the Plugins folder (I grabbed a copy from the ruby install and placed it there)
                              • place clear_ruby_console.rb in your Plugins folder.
                              • "Clear Ruby Console" should appear at the bottom of the Window drop-down menu after you start SketchUp

                              [attachment=0:2o2wyuvn]<!-- ia0 -->clear_ruby_console.rb<!-- ia0 -->[/attachment:2o2wyuvn]

                              clear_ruby_console.rb

                              
                              > # you need Win32API.so in the Plugins folder for this to work.
                              > # I grabbed a copy from the ruby install and placed it there
                              > require 'Win32API' 
                              > 
                              > 
                              > 
                              > def clear_ruby_console
                              > 
                              > 	# Find a window called Ruby Console
                              > 	# (Note; if there is more than one, then this may not work)
                              > 	fw = Win32API.new("user32.dll", "FindWindow", ['P', 'P'], 'N')
                              > 	pw=fw.call(0, "Ruby Console")	
                              > 	if (!pw)
                              > 		puts "Ruby Console not found"
                              > 		return
                              > 	end#if
                              > 	
                              > 	# get the text output window in the Ruby Console
                              > 	fw_ex = Win32API.new("user32.dll", "FindWindowEx", ['N', 'N', 'P', 'P'], 'N')
                              > 	h_text = fw_ex.call(pw, 0, "Edit", 0) # Text Input for Ruby Console
                              > 	if (!h_text)
                              > 		puts "Ruby Console text window not found"
                              > 		return
                              > 	end#if
                              > 	
                              > 	# get the output window
                              > 	h_output = fw_ex.call(pw, h_text, "Edit", 0) # Output for Ruby Console
                              > 	if (!h_output)
                              > 		puts "Ruby Console output window not found"
                              > 		return
                              > 	end#if
                              > 	
                              > 	# Clear the text in the ruby output
                              > 	# by sending it an empty string
                              > 	sm = Win32API.new("user32.dll", "SendMessage", ['N', 'N', 'N', 'P'], 'N')	
                              > 	wm_settext = 0x000c # windows constant to set text
                              > 	sm.call(h_output, wm_settext, 0, "")	
                              > 	
                              > 	#You can change this to whatever message you want to display
                              > 	#after the console is cleared.
                              > 	puts "--- Ruby Console Cleared ---"
                              > 			
                              > end#def
                              > 
                              > # Add to Windows menu
                              > if ( !$clear_console_loaded)
                              >    UI.menu("Window").add_item("Create Ruby Console") {clear_ruby_console}
                              >    $clear_console_loaded = true
                              > end
                              > 
                              > 
                              > 
                              

                              Thanks, it works! And I learned something new (win32api calls) with this example of yours. Thanks!
                              Yet, be careful there... I am sure you know about this but, in ruby only "false" and "nil" evaluate to "false", "C language" NULL does not, so you need to test against 0(zero) instead of using the "not operator" on the return values, which are numbers and therefore using "not" always yield to false in ruby.

                              1 Reply Last reply Reply Quote 0
                              • M Offline
                                MartinRinehart
                                last edited by 14 Jun 2010, 14:49

                                t=28571clear.jpg

                                Clears input and output windows. Toggle output off and on to clear just output.

                                http://forums.sketchucation.com/viewtopic.php?f=323&t=28571

                                Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                                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