cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
john_madden
Level VI

Gracefully exiting an add-in

I am writing an add-in to operate on the Current Data Table(). I want the add-in to exit gracefully without doing anything if:

(a) there is no Current Data Table()

or

(b) the Current Data Table has <2 columns.

I can't seem to get this to happen. I installed the add-in and looked at the .jmpcust file that was generated. Up at the very top of the script where the comment says "Variables and functions declared here are scoped to the Application namespace", I note this code:

dt = Current Data Table();
If(Is Empty(dt),
	Quit Application()
);

Quit Application = Function({},
	Current Window() << Close Window;
	Throw()
)

which I *think* was inserted by Application Builder (and not by me).

It would seem to be right for accomplishing (a), but instead my add-in charges ahead in the absence of a Current Data Table() and opens its dialog window.

Can someone help me out?

 
 
1 ACCEPTED SOLUTION

Accepted Solutions
mikedriscoll
Level VI

Re: Gracefully exiting an add-in

Do you mean you would like the script to stop without any feedback to the user? If so, replace the throw("info text") with stop() and the script will terminate there. I imagine it would work the same in the application script but I've never worked with that.

View solution in original post

4 REPLIES 4
mikedriscoll
Level VI

Re: Gracefully exiting an add-in

I tried to debug that in the script editor and it closed the editor without saving. I didn't realize what happened until I re-did it and ran it again.  The function should be defined before it is called, so that seems out of order.  

 

I've never used the application builder. I do this sort of control at the script level, just before the GUI is called. Basically my scripts look like:

1. initial stuff up top

2. Main script function

3. assign dt and decide to proceed to GUI or not

4. GUI, where the ok button calls the script function.

 

Here's how I check for a data table. You could use a modified version of this and also check for ncol(dt) >= 2.  

dtData = current data table();

try(dtData << get name, throw(New Window("No Data Table Found",<<Modal, textBOx("No open data tables found.                "),textbox(" "), 
		ButtonBox("OK"))));

 

john_madden
Level VI

Re: Gracefully exiting an add-in

I think I found a solution in the meantime looking at one of txnelson's posts. In the application script, I put:

If( N Table() == 0,
	Throw( "Add-in requires an open data table." )
);

dt = Current Data Table();

If( N Cols( dt ) < 2,
	Throw(
		"Add-in requires a table with at least two columns."
	)
);
 
john_madden
Level VI

Re: Gracefully exiting an add-in

But I'd still be interested in knowing how to Throw() without causing any error dialog box to appear at all. I think that recent post of txnelson addresses this, but I'm confused about what it does and how it works.

 
mikedriscoll
Level VI

Re: Gracefully exiting an add-in

Do you mean you would like the script to stop without any feedback to the user? If so, replace the throw("info text") with stop() and the script will terminate there. I imagine it would work the same in the application script but I've never worked with that.