by thomthom » Wed Feb 24, 2010 7:36 pm
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.
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by tbd » Wed Feb 24, 2010 9:12 pm
last time when I checked it didn't help much because the whole text will be back on the print/puts
-

tbd
-
- Posts: 948
- Joined: Wed Nov 14, 2007 10:47 am
- Location: Romania
- Name: TBD
-
by Chris Fullmer » Wed Feb 24, 2010 9:33 pm
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. 
-

Chris Fullmer
- SketchUp Team

-
- Posts: 6916
- Joined: Wed Nov 21, 2007 3:21 am
- Location: Boulder, CO
- Name: Chris Fullmer
- Operating system: Windows
- SketchUp version: 2013
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by thomthom » Wed Feb 24, 2010 9:45 pm
TBD wrote: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?!?
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by thomthom » Thu Feb 25, 2010 8:38 am
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!
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by thomthom » Thu Feb 25, 2010 9:45 pm
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.
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by jessejames » Thu Feb 25, 2010 11:16 pm
thomthom wrote: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!
-
jessejames
-
- Posts: 166
- Joined: Sat Dec 27, 2008 3:30 am
by TIG » Fri Feb 26, 2010 10:15 am
thomthom wrote: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
-

TIG
- Global Moderator
-
- Posts: 20380
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by thomthom » Fri Feb 26, 2010 10:23 am
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.
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by TIG » Fri Feb 26, 2010 10:45 am
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
-

TIG
- Global Moderator
-
- Posts: 20380
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by thomthom » Fri Feb 26, 2010 12:04 pm
Excellent TIG. Now - if only we found the author so we could get this posted publicly...
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Jim » Fri Feb 26, 2010 3:57 pm
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
-
Jim
- Global Moderator
-
- Posts: 4678
- Joined: Mon Nov 12, 2007 10:13 pm
- Location: ohio
- Name: Jim
- Operating system: Windows
- SketchUp version: 2017
- License type: Pro
- SketchUp use: hobby
- Level of SketchUp: Intermediate
-
by Al Hart » Fri Feb 26, 2010 7:58 pm
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 - Code: Select all
# 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
- PluginStore Author

-
- Posts: 1623
- Joined: Sun Nov 18, 2007 3:54 pm
- Location: Centennial, Co
- Name: Al Hart
- Operating system: Windows
- SketchUp version: pre-2013
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by filsaz » Thu Jun 10, 2010 10:57 pm
Al Hart wrote: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 - Code: Select all
# 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.
-
filsaz
-
- Posts: 1
- Joined: Wed Nov 05, 2008 8:45 pm
by Ad Machine » 5 minutes ago
-
Ad Machine
- Robot
-
- Posts: 2012
-
Return to Developers' Forum
|