An Easy Way to Launch Stand-Alone Apps from Eclipse

In a previous post (Launch Stand-Alone Apps from Eclipse), I discussed how to implement a plug-in script that can launch any stand-alone app. This is helpful because stand-alone apps can’t be launched from Eclipse directly (only plug-in scripts can).

The method I described in that post works well, but it’s still somewhat complex. It requires a separate text file to keep track of the available stand-alone apps. It also shows a dialog box with the apps to choose from, so there’s an extra step before launching the desired app.

I found a way to launch stand-alone apps from Eclipse that is identical to launching plug-in scripts. You can even put them in the Tools menu, just like plug-in scripts. In this post, I’ll show you how to do this.

The idea is to create a separate project in your Visual Studio solution, and that project will act as a plug-in script. It’s only job is to find the actual stand-alone app (an executable file) and launch it.

First, in your stand-alone solution add a new class library project. If your main project is called “MyApp,” you can name the new project “MyApp.Script.” In the solution explorer, right-click on the project and rename the assembly to “MyApp.esapi” (of course, start with the name of your main project, but plug-in script assemblies must end with “.esapi”).

Add references to the Varian assemblies (VMS.TPS.Common.Model.API and VMS.TPS.Common.Model.Types). Also, add a reference to the PresentationFramework (in the Assemblies section), which we’ll need for showing a message box.

Open the automatically created Class1.cs file and rename it to Script.cs (it doesn’t have to be this name, but it’s what I like to name my main plug-in script class). Replace the contents of this file to the following:

As you can see, the code uses Process.Start to launch the application. The path of the application is assumed to be the first executable file in the directory where this script is located. This is not true, yet, but we’ll fix that next.

Finally, reference the plug-in script project from your main stand-alone project. This will cause the build system to copy the plug-in script files to the same directory as your stand-alone files.

Now, in Eclipse you should be see “MyApp.esapi.dll” when you choose your stand-alone’s directory in the Scripts dialog box. When you run it, it will immediately launch your app. The plug-in script ends as soon as the stand-alone app is launched, so you’ll be able to close the Scripts dialog box and go back to using Eclipse.

4 thoughts on “An Easy Way to Launch Stand-Alone Apps from Eclipse

  1. J

    Hi,
    Should this work in a Citrix environment as well? This worked to launch my standalone app on a thick-client Eclipse Box but would like to now run it via Citrix. Is this possible?

    Reply
  2. Michael

    Thanks for the post, I got it to work for a simple app. How could I make the scriptcontext available in the main program? I’m working behind a Cirtix environment so would like to get this working.

    Reply
    1. Carlos Anderson Post author

      Hi Michael,

      You can’t make the ScriptContext object available to the stand-alone app. The stand-alone app still needs to create an Application object and open the desired patient. However, you can tweak the code above to pass the context information to the stand-alone app as command-line arguments. The app would need to read these arguments and interpret them as context information. For example, you could pass the current patient ID, course ID, and plan ID. The app would need to open these items itself since there’s no ScriptContext object. I intend to write another blog post about this.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *