@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.