Subscribe Bookmark RSS Feed

C# automation, issue opening and closing JMP application

vjeff

Community Member

Joined:

Jun 23, 2011

Hello All,

I've had good success when using C# to automate JMP, but I'm getting some unexpected behavior on open and close of the JMP application.

I open JMP with:
JMP.Application app;
app = new JMP.Application ();

This works, but if I have an instance of JMP already open and running, it will hijack it. Is there any way to always spawn a new application?

I close with:
app.CloseAllWindows();
app.Quit();

Again, this closes what I opened or hijacked. Is there any way to just close the one that I opened? And if I didn't open any, to not close anything?

Thanks!

--Jeff

P.S. Using JMP version 7.


Message was edited by: vJeff
1 REPLY
mattf

Community Trekker

Joined:

Jun 23, 2011

Hi Jeff:

I, too, wondered about this behavior, and after spending too much time trying to figure out how
to make it work gave up and asked the good folks @ JMP Tech support, who, of course, had the
answer immediately. It behaves that way by design (that is, as a single session, multiple-use
automation server), and is relativly simple to change to the other behavior if desired (that is,
multi-session single use).

I was directed to the answer here:

Usage Note 11089: How to enable JMP as a single use server for automation
http://www.jmp.com/support/notes/11/089.html

"Traditionally, JMP has run as a multiple use automation server.... "
That is, like MS Powerpoint

"...To enable JMP as a single user server, modify the registry key ... \Multiple -> ...\Single"
That is, like MS Word and Excel

See also:
GetObject and CreateObject behavior of Office automation servers
http://support.microsoft.com/kb/288902
How to obtain the window handle for an Office Automation server
http://support.microsoft.com/kb/258511

Example code snipptet in TCL (very similar to C#, Perl, Python, etc. pick your favorite scripting tool,
the calls to COM objects are much the same.)

Default \Multiple behavior
#################################
# load an add-on package into TCL to enable easy access to COM calls
# included in the ActiveState TCL Distro http://www.activestate.com/activetcl/
# www.vex.net/~cthuang/tcom/
# wiki.tcl.tk/1821
package require tcom

# attach to an existing session
set jmp3 [::tcom::ref getactiveobject "JMP.Application" ];

# fire up JMP (Creates a new JMP session if one does not already exist. If one does exist,
then attaches to it. Will not/cannot create a second )
set jmp [::tcom::ref createobject "JMP.Application" ];
$jmp -method Visible 1


Single use server for automation
#################################
# fire up jmp (creates two independent sessions, or a single call creates a new session if one exists)
set thing1 [::tcom::ref createobject "JMP.Application" ];
set thing2 [::tcom::ref createobject "JMP.Application" ];
$thing1 -method Visible 1
$thing2 -method Visible 1
# note the two separate object references created, thing1 and thing2, they can be controlled indepently

Best regards,
-Matt