Dear All,
(JMP Pro 16.1.0, Win10)
I have an issue related to a previous post of mine here, if you're interested in some "back story".
The primary issue I'm having now is that the Throw() command is not working as expected. In my code (see at end for full code), I have in a few places a test to see whether there is currently an open graph builder report, looks like this, and it's wrapped in and Expr() statement:
If( Is Empty( Current Report() ) == 1,
Throw( "No Graph Builder Window is Open" )
);
The problem is, whenever I run the code (as if running it from a toolbar hotbutton), it seems to skip these lines and ignores if there is no report open. But, when I run the code "line by line", then it will correctly catch that there is no report open and notify the user.
I'm trying to write code to be distributed to users across my organization and trying to make it robust enough to handle different kinds of situations, e.g. If a user has one or more data tables open and/or one or more projects open (which can contain multiple data table).
Here's the concept of the code (issue occurs at item 6): a user is creating a graphic in Graph Builder, then wants to do a routine modification of the graphic (see link above for details on that), the user then clicks the toolbar hotbutton to perform said action.
- The code runs the Graphic_Expr expression to determine the location of the graphic -- is it in a "stand alone" data table, or within a project (only one option can be selected). -> (go to)
- Depending on which checkbox is selected, code then runs either the dt_win_Expr or prj_win_Expr code (right now, I only have it set up for the data table option as I test the code, but ideally should function more or less the same in the end). -> (go to)
- If a standalone data table, then it runs dt_win_Expr and creates a window for the user to select the data table where the graphic they want to edit resides. Recall that the user could have more than one data table open with potentially more than one Graph Builder open. | (or)
- Similarly, if the user selects a project, it will run the prj_win_Expr (not completed yet) to have the user select which project (if more than one open) and subsequent data tables within that project. -> (go to)
- Once a data table is selected, whether standalone or within a project, the code runs the SquarifyWin_Expr expression. The first thing it does here is test whether there is in fact a Current Report in existence -- the If() code from above (I might need to modify and test whether the current report is a Graph Builder or not). **This is where the code does NOT function as expected. Even if there is no Graph Builder open, it will continue on with the rest of the code when it should throw the warning.** If everything works....-> (go to)
- Based on the pixel dimensions and whether to squarify, the code then runs the RprtUpdate_Expr expression, where it sends the desired updates to the Graph Builder report.
I hope this description makes sense and helps to put into context what my desired programming path/functionality is.
Many thanks in advance for any help in finding a solution. Full JSL code at end.
Thanks!,
DS
Names Default To Here( 1 );
Clear Symbols();
RprtUpdate_Expr = Expr(
gb = Current Report()[Outline Box( 1 )] << Get Scriptable Object;
Report( gb )[framebox( 1 )] << FrameSize( widthN, heightN );
theMax = Max( Report( gb )[axisbox( 1 )] << get max, Report( gb )[axisbox( 2 )] << get max );
theMin = Min( Report( gb )[axisbox( 1 )] << get min, Report( gb )[axisbox( 2 )] << get min );
Report( gb )[framebox( 1 )] << Xaxis( Min( theMin ), Max( theMax ) );
Report( gb )[framebox( 1 )] << Yaxis( Min( theMin ), Max( theMax ) );
Report( gb )[framebox( 1 )] << AddGraphicsScript(
xmin = X Origin();
xmax = X Origin() + X Range();
ymin = Y Origin();
ymax = Y Origin() + Y Range();
Pen Color( "blue" );
Pen Size( 1 );
Line Style( "solid" );
Line( {xmin, ymin}, {xmax, ymax} );
);
);
SquarifyWin_Expr = Expr(
If( Is Empty( Current Report() ) == 1,
Throw( "No Graph Builder Window is Open" )
);
nwin = New Window( "Enter Size of Desired Graph",
<<Return Result,
<<On Validate,
V List Box(
Outline Box( "Please enter pixel size of graph", <<Set Font Size( 12 ) ),
Lineup Box( N Col( 2 ), Spacing( 3, 3 ),
Text Box( "Width" ),
width_var = Number Edit Box( 250 ),
Text Box( "Height" ),
height_var = Number Edit Box( 250 ),
sq_input = Check Box( "Squarify Graph?", <<Set( 1 ) )
),
H List Box(
Button Box( "OK",
If( (sq_input << Get) == 1,
widthN = nwin[Number Edit Box( 1 )] << Get;
heightN = widthN;
nwin << Close Window;
RprtUpdate_Expr;
);
If( (sq_input) << Get == 0,
widthN = nwin[Number Edit Box( 1 )] << Get;
heightN = nwin[Number Edit Box( 2 )] << Get;
nwin << Close Window;
RprtUpdate_Expr;
);
),
Button Box( "Cancel", nwin << Close Window )
)
)
);
);
dt_win_Expr = Expr(
dt_list = Get Data Table List();
dt_win = New Window( "Select the data source",
<<Return Result,
<<On Validate,
Panel Box( "Choose a data table",
dt = List Box( dt_list, max selected( 1 ), dt_select = Data Table( (dt << get selected)[1] ) ),
H List Box(
Button Box( "OK",
dt_win << Close Window;
SquarifyWin_Expr;
),
Button Box( "Cancel", dt_win << Close Window )
)
)
);
);
Graphic_Expr = Expr(
GraphicWin = New Window( "Location of graphic",
<<Return Result,
<<On Validate,
V List Box(
Outline Box( "Is graphic in a data table or project?", <<Set Font Size( 12 ) ),
Lineup Box( N Col( 4 ), Spacing( 3, 3 ),
dt_chkbx = Check Box( "Data Table", If( (prj_chkbx_state = prj_chkbx << Get) == 1, prj_chkbx << Set( 1, 0 ) ) ),
prj_chkbx = Check Box( "Project", If( (dt_chkbx_state = dt_chkbx << Get) == 1, dt_chkbx << Set( 1, 0 ) ) ),
Button Box( "OK",
If( (dt_chkbx_state = dt_chkbx << Get) == 1,
GraphicWin << Close Window;
dt_win_Expr;
);
If( (prj_chkbx_state = prj_chkbx << Get) == 1,
GraphicWin << Close Window;
prj_win_Expr;
);
),
Button Box( "Cancel", GraphicWin << Close Window )
)
)
);
);
Graphic_Expr;