Launching non-blocking external applications
-
Wow.... How intimidating. My first post ever, and it's the first topic of the forum....
In any event, I'm a bit new to both Ruby in general and SketchUp in particular, so hopefully I'm not asking a question that already been addressed. (I couldn't seem to find this mentioned anywhere else -- not on the old forum, anyway.) If this is in fact a repeat question, then just cuff me.
I'm having a peculiar problem. I'm trying to create a very simple plug-in: it puts a menu item into the "Plugin" menu, and when you select it, all it does is launches a (totally unrelated) external application -- say, Window's Spider Solitaire. I've found that I can actually indeed do this, but only as a blocking call -- SketchUp becomes wholly non-responsive while Solitaire is executing, and only becomes responsive again when Solitaire closes.
That was fine, until I was playing with another third-party plugin (the "Podium" plugin available off Sketchup's Plugin site). If I run the Podium plugin before trying to launch Spider Solitaire, then all of a sudden, the call to Solitaire is no longer blocking: Solitaire can run fine in the background and SketchUp remains responsive. This behaviour persists even after I close the Podium pop-up window. So long as I run Podium first, the call to Solitaire is non-blocking; if I don't run Podium first, then Solitaire blocks SketchUp.
I'm afraid that the call to launch Solitaire is a rather dumb one: I'm escaping to the shell and calling a batch file. (The call is:
system("c:/[...]/mySolitaireLauncher.bat"
) I'm doing it that way because I need to change the working directory before calling Solitaire and can't figure out how to do that without invoking a .BAT file. (That's a topic for another thread though.) Still, I don't really see why the behaviour would change because of a third-party plugin.
Ideally, I'd like to launch the Solitaire application as a non-blocking call, without needing a dummy call to Podium. I wanted to simply use the fork call, but it turns out this isn't implemented under Windows. Does anyone know how it's done?
Many thanks,
Kevin
-
I'm far from knowledgeable about this stuff but does this help you at all? It is a plugin to call the windows calculator. The calculator can be minimized so you can return to SU. Just a stab in the dark.
Here's the script:
*require 'sketchup.rb'
-----------------------------------------------------------------------------
Add item "calculator" to the Draw menu.
First check for existing menu load
if( not file_loaded?("calc.rb") )
UI.menu("Plugins").add_item("Calculator") { UI.openURL("calc.exe") }
end
-----------------------------------------------------------------------------
file_loaded("calc.rb")*
-
Ah, super, that actually did work! Good timing! I was about --| |-- this close to trying to figure out the WIN32API package.... Thanks for helping dodge that bullet (at least temporarily!).
Kevin
-
Or you work with a thread:
Thread.new do system(systemcall, systempara) # set "finished flag" end
If need to have set a "return flag", you can set it in the thread.
azuby
-
Huh. In fact, I actually like that solution even more. (It just seemed weird to call an executable through an openURL() call.) -- And, as an extra bonus, the Thread solution does indeed work too!
Hmph. I should have actually tried it myself before resorting to posting. I thought of that option a couple of days ago, but the book I've got seemed to suggest that Threads always blocked on each other (which doesn't make any sense in hindsight, 'cause what would be the point of threads?). Anyway, hopefully this post will be useful to someone else.
In any event... -- thanks!
Kevin
-
Interesting solution Azuby. I have to check how if it allows to pass parameters as well.
ThanksTomasz
Advertisement