• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Launching non-blocking external applications

Scheduled Pinned Locked Moved Developers' Forum
6 Posts 4 Posters 9.6k Views
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.
  • K Offline
    kevd
    last edited by 13 Nov 2007, 23:11

    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

    1 Reply Last reply Reply Quote 0
    • D Offline
      Dave R
      last edited by 14 Nov 2007, 02:21

      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")*

      Etaoin Shrdlu

      %

      (THERE'S NO PLACE LIKE)

      G28 X0.0 Y0.0 Z0.0

      M30

      %

      1 Reply Last reply Reply Quote 0
      • K Offline
        kevd
        last edited by 14 Nov 2007, 15:29

        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

        1 Reply Last reply Reply Quote 0
        • A Offline
          azuby
          last edited by 14 Nov 2007, 21:37

          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

          *error initus :: Blocks | CurrentDate | d/Code | extensionmanager | FFlipper | HideEdges | MeasuredArea | ModelHistory | PluginsHelp | PronButton | SAWSO | SCP | SU²CATT

          Bad English? PM me, correct me. :smile:**

          1 Reply Last reply Reply Quote 0
          • K Offline
            kevd
            last edited by 14 Nov 2007, 22:06

            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

            1 Reply Last reply Reply Quote 0
            • T Offline
              tomasz
              last edited by 17 Nov 2007, 10:51

              Interesting solution Azuby. I have to check how if it allows to pass parameters as well.
              Thanks

              Tomasz

              Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              1 / 1
              • First post
                6/6
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement