How to check showRubyPanel is ready to accept puts
-
I haven't checked the load order of this, but you could try to use the -RubyStartup argument and see if that loads the file before the rest of the plugins in the Plugins folder: http://www.thomthom.net/thoughts/2013/04/sketchup-command-arguments/
-
Well, I'm already sure it load it first
The problem here, is that I can't seem to open the Ruby Console before continuing to load any other plugin. Using any timer will only delay opening the Ruby Console as well. When you have a lot of plugins to load, eventually the puts from loading the last plugins will be displayed in the Ruby Console. It's like the Ruby Console is only opening, taking time in between loading other plugins.
So I'm now trying to move all plugins to "plugins/delayed/", all but one that opens the Ruby Console and waits for 2 seconds to load the others with using:
`UI.start_timer(3, true) { require_all(Sketchup.find_support_file("Plugins") + "/delayed") }
`
The thing I need now is not a timer, but a check it the Ruby Console is fully loaded and ready. So, how can one know if the Ruby Console is open? -
maybe you can call winapi to try to search for the Ruby Console window and see if it returns something.
-
@onidarbe said:
Well, I'm already sure it load it first
The problem here, is that I can't seem to open the Ruby Console before continuing to load any other plugin. Using any timer will only delay opening the Ruby Console as well. When you have a lot of plugins to load, eventually the puts from loading the last plugins will be displayed in the Ruby Console. It's like the Ruby Console is only opening, taking time in between loading other plugins.
So I'm now trying to move all plugins to "plugins/delayed/", all but one that opens the Ruby Console and waits for 2 seconds to load the others with using:
`UI.start_timer(3, true) { > require_all(Sketchup.find_support_file("Plugins") + "/delayed") > }
`
The thing I need now is not a timer, but a check it the Ruby Console is fully loaded and ready. So, how can one know if the Ruby Console is open?
Whenever you rub against stuff like this, you need to ask yourself whether what you're trying to do is a good idea.
I'd have a think about whether you can't solve this another way; there is no way of knowing that your request has been realized - ie the console is open. (Short of nasty hacks looking through a window hierarchy). -
The Win32API hack has been covered in this forum before, and may be one of Jim's snippets. Did you check the Snippet Index ?
But this will not work for the Mac. Sorry but that feature has not yet been implemented in the API.
Secondly.. I always use a
Float
value for the delay, it seems to work better. -
Why do you need to have the Ruby Console open before everything else loads?
Debug loading issues?
If that is the case - you can redirect $std_out and $std_err to make a Win32 call to OutputDebugString and capture the output with an application like DebugView. -
Thank you all, I'll look it to it all...
-
Opening the console, then opening a message box and then using "puts" will work.
Sketchup.send_action('showRubyPanel;') UI.messagebox "" puts "hi"
Its annoying because you always have to hit enter as SU starts, but it works.
-
if you really want to be the first event, using the 'correct' Plugins folder...
then...
name a file, with what you assume is the top rank, first loading filename...
add this to your file.msg = $" UI.messagebox (msg.sort.join("\n").to_s) Sketchup.send_action('showRubyPanel;') puts (msg.sort.join("\n").to_s)
then modify the name until, it is the only 'Plugins' ruby shown as loaded, i.e. last on generated list...
if it's last
when you hit 'OK'
showRubyPanel, will be the first thing to happen, before the load continues...
then, you can remove the UI.messagebox from your script, knowing your first in line...As explanation...
on a mac [ __always_meFirst ], will appear in the 'folder' above [ !always_meFirst ], although the second has higher precedence in the load order...john
EDIT<<< addedputs (msg.sort.join("\n").to_s)
to show nothing snuck in there... -
yeah, but
UI.messagebox
is again disturbing a quick save-and-test my plugins!I'm still fooling around with the Win32API, to know when the Ruby Console window is open. In the meantime I'm just waiting 2 seconds before my plugins are loaded with this:
To make it ready for RDZ I added:
...\plugins\mr_plugins.rbrequire 'sketchup.rb' # Don't know why, but everyone is adding these line? require 'extensions.rb' # Don't know why, but everyone is adding these line? mr_plugins = SketchupExtension.new "mr_plugins", "mr_plugins/mr_!main.rb" mr_plugins.copyright= "Copyright 2014" mr_plugins.creator= "onidarbe () gmail" mr_plugins.version = "2013 jan 06" mr_plugins.description = "Adds all ../plugins/mr_plugins/*.rb" Sketchup.register_extension mr_plugins, true
This plugin will then load all my plugins in a sub-folder after 2 seconds, to be sure that the Ruby Console is open and ready to receive
puts
:
...\Plugins*mr_plugins*\mr_!main.rbmodule MR if !file_loaded?(File.basename(__FILE__)) UI.start_timer(2, true){ require_all(Sketchup.find_support_file("Plugins") + "/mr_plugins/") } file_loaded(File.basename(__FILE__)) end #if end #module
Finally this code will add a menu-item which could be checked to enable/disable opening the Ruby Console:
...\Plugins*mr_plugins*\mr_openRubyConsoleOnStart.rbmodule MR @pluginPath = Sketchup.find_support_file("Plugins") def self.openRubyConsoleOnStart # onidarbe 2013-01-07 # Delete or create a plugin file that opens the Ruby Console on start of Sketchup. # Because the filename starts with a "!" it will alphabetically start first. # The Ruby Console takes some time to load in-between loading other plugins!" if FileTest.exist?(@pluginPath + "/!openRubyConsoleOnStart.rb") File.delete(@pluginPath + "/!openRubyConsoleOnStart.rb") UI.menu("Windows").set_validation_proc(@menuItem){MF_UNCHECKED} else file = File.new(@pluginPath + "/!openRubyConsoleOnStart.rb", "w") file.puts("# Placed here with #{File.basename(__FILE__)} to open the Ruby Console at start.") file.puts("# Filename starts with a '!' to start first as plugins starts alphabetically.") file.puts("# The Ruby Console takes some time to load in-between loading other plugins!") file.puts("Sketchup.send_action 'showRubyPanel;'") #to open Ruby Console file.close UI.menu("Windows").set_validation_proc(@menuItem){MF_CHECKED} end end if !file_loaded?(File.basename(__FILE__)) @menuItem = UI.menu("Windows").add_item("Open Ruby Console on start [MR]") {MR;;openRubyConsoleOnStart} if FileTest.exist?(@pluginPath + "/!openRubyConsoleOnStart.rb") p @menuItem UI.menu("Windows").set_validation_proc(@menuItem){MF_CHECKED} end if file_loaded(File.basename(__FILE__)) end end #module
Now if I could know that the Ruby Console is open, then I don't need to add an other menu-item! I could just restore the last situation, opening the Console when it was open on closing SU.
-
sorry,
I can't quite grasp your intentions...
you can start SU with NO plugins, and then load any single [or set] ruby/'s, from any location, including the Plugins Directory, in any order quite easily...
is that what your after?
john
-
Because I need to swap very often between Notepad++ and SU while writing code I don't want to do a lot of stuff like saving, loading, typing, ... So I don't like opening the Ruby Console and loading plugins manually.
I also like the Ruby Console to be ready to accept puts while my plugins are loading, for debugging reasons. I already managed Notepad++ to auto-saves everything upon unfocusing, and 1 short-cut to reload them in SU. But sometimes SU needs to restarted to really have all the old stuff out of it like methods and variables.
So I like SU to automatically restart, open the Ruby Console and be ready to accepts puts from my plugins while they are loading
I would also like to find out if the Ruby Console is open, so I don't need that menu-item to enable/disable the Ruby Console at start. Seems I need to use Win32API.
-
@onidarbe said:
Seems I need to use Win32API.
most probably... for the Notepad++ side of things.
I understand more what your doing now...
I have a similar setup that uses 'Applescript' and 'Unix' to let me work in 'dev-mode', I struggled to get it to work for many versions.
I'm very happy with it now, and it is possibly portable, if you want to have a look I'll PM you a copy...
It now functions on a very simple premies.
Let SU do the SU bits and only do what it can't with other tools...
when you use
Sketchup.plugins_disabled = true
=> 'only' the standardSketchup.find_support_file("Plugins")
are disabled.'Ruby Console' can be opened from any other other loaded path.
I have two different 'loader files'
One is in "../Plugins/My_Folder/my_file", it has a cmd that togglesSketchup.plugins_disabled = true : Sketchup.plugins_disabled = false
Then, I use the "Tools" folder to hold a small ruby that basically... [sudo code]my_file = ( Sketchup.find_support_file("my_file.rb", "Tools") ).sub( "Tools", "Plugins") if Sketchup.plugins_disabled? && FileTest.readable?( my_file ) "Sketchup.send_action 'showRubyPanel;'" load(my_file) else ignore_me end
john
Advertisement