How to prevent Run in Fit Model from producing a report?I am writing a script that does the following:
- Opens a Fit Model window,
- Allows the user to populate it using the Macros and other functionality in the Fit Model window,
- Allows the user to click Run, at which point a possibly time-intensive calculation is performed and a report is produced.
The calculation that is performed when Run is clicked is produced by a script stored in the Run button. This script produces a report, which is what the user should see. However, because the script is added to the Run button, that desired report appears, but is then followed by the Fit Least Squares report that Run produces on its own. The Fit Least Squares report is meaningless to the user.
The script below illustrates the problem. In that script, the expression in the Run button, "runExpr", simply creates a clone data table; this is to simplify the illustration. In the actual script, that expression (runExpr) performs a lot of analysis based on the effects entered in the Fit Model window. Also, in the actual script, the user populates the Fit Model window interactively; I populated the Fit Model window in the script below for convenience.
Names Default To Here( 1 );
runExpr = Expr(
// Creates a clone data table for illustration;
dt << Subset( Output Table( "Clone Table" ), All rows );
);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
fmSLS = Fit Model(
Y( :weight ),
Effects( :age, :height, :age * :height ),
Personality( "Standard Least Squares" ),
Emphasis( "Minimal Report" ),
);
r = fmSLS << Report;
r[Button Box( 9 )] << Set Script( runExpr);
When you click Run, as a user would, the clone table appears, but the window on top is the Fit Least Squares report produced by the Run command. I would like to prevent that report from appearing.
To that end:
- I have tried using Throw() and Stop() in runExpr, but to no avail.
- I considered using a modal window, but I need the Macro functionality in the Fit Model window, and I can't see how to make a modal window help.
- The only way I can think of even to address the Fit Least Squares report is to add a timing loop to the script as illustrated below. But this is fraught with peril. There is no way to know how long it will take for the runExpr to complete, and if the user decides not to click Run, the script just keeps running until it times out.
Any thoughts or help would be greatly appreciated!
Names Default To Here( 1 );
runExpr = Expr(
// Creates a clone data table for illustration;
dt << Subset( Output Table( "Clone Table" ), All rows );
fm_Flag = 1
);
fm_Flag = 0; // Sets flag for timing
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
fmSLS = Fit Model(
Y( :weight ),
Effects( :age, :height, :age * :height ),
Personality( "Standard Least Squares" ),
Emphasis( "Minimal Report" ),
);
r = fmSLS << Report;
r[Button Box( 9 )] << Set Script( runExpr; fm_Flag = 1 );
For( i = 1, i <= 100, i++,
If(fm_Flag < 1, Wait(0.5), windowsopen = Get Window List(); windowsopen[nItems(windowsopen)] << Close Window; Stop() )
);
ScriptingRe: How to prevent Run in Fit Model from producing a report?I don't see how to modify the script that you attach to the Run button box, but you can find and close the window afterward. See this illustration:
fm = Current data Table() << Fit Model(
Y( :weight ),
Effects( :age, :sex, :height ),
Personality( "Standard Least Squares" ),
Emphasis( "Effect Leverage" )
);
fls = fm << Run;
window = Get Window List();
For( w = 1, w <= N Items( window ), w++,
If( Contains( window[w] << Get Window Title, "Fit Least Squares" ),
window[w] << Close Window;
Break();
);
);
Re: How to prevent Run in Fit Model from producing a report?You are correct. I tried to modify my illustration but the script that is attached to the button box is evaluated before the Fit Least Squares report is created, so it is ineffective.
Names Default to Here( 1 );
run expr = Expr(
// desired report
personality = Report( fm )[ComboBox(1)] << Get Selected;
Show( personality );
// undesired report
window = Get Window List();
For( w = 1, w <= N Items( window ), w++,
If( Contains( window[w] << Get Window Title, "Fit Least Squares" ),
window[w] << Close Window;
Break();
);
);
);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
fm = dt << Fit Model(
Y( :weight ),
Effects( :age, :sex, :height ),
Personality( "Standard Least Squares" ),
Emphasis( "Minimal Report" )
);
Report( fm )[ButtonBox(9)] << Set Script( run expr );
// nothing after this point
Re: How to prevent Run in Fit Model from producing a report?How much of the Model Specification dialog box do you need? I can't help but think you would be better served replacing that step with a new window catered to your exact needs. Examples in this post might help:
https://community.jmp.com/t5/JMPer-Cable/Prompting-for-columns-totally-modally/ba-p/189647
If you want to use the Model Specification window, you could give the user a new button to click on:
Names Default to Here( 1 );
run expr = Expr(
// desired report
personality = Report( fm )[ComboBox(1)] << Get Selected;
Show( personality );
);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
fm = dt << Fit Model(
Y( :weight ),
Effects( :age, :sex, :height ),
Personality( "Standard Least Squares" ),
Emphasis( "Minimal Report" )
);
// Show error if user clicks the wrong button
(fm << XPath("//ButtonBox[@title='Run']"))[1] << Set Script( New Window( "Use other bottom",
Text Box("Woops...\!n\!nPlease use the button at the bottom of the fit model dialog to launch this script.")));
// Button the user should click on
(fm << XPath("//OutlineBox"))[1] << Append(Button Box("Launch custom script", run expr; fm << Close Window;));<BR />
Re: How to prevent Run in Fit Model from producing a report?Why are you using the Fit Model dialog if you do not want the Fit Least Squares platform? There might be another way to achieve what you want.