cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
SDF1
Super User

Help with JSL Throw() not functioning as expected

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.

 

  1. 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)
  2. 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)
  3. 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)
  4. 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)
  5. 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)
  6. 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;
2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Help with JSL Throw() not functioning as expected

Have you checked if there is any prints in JMP Log? The Throw might trigger but there just is no "error window". At least when I work with addins I use custom error modal window because Throw doesn't create error window like when run as a script.

Modal Dialogs has fairly simple alert function you could use instead of Throw (you can also throw but use modal window to show the error to user).

 

Edit:

Found one function I have used for info modal windows:

Names Default To Here(1);


mini_modal_window = function({title, text, text_icon = "BlankIndex", window_icon = "NewApplication"}, {Default Local},
	New Window(title, <<modal, << show toolbars(0), << show menu(0), << Set Window Icon(window_icon),
		H List Box(
			Icon Box(text_icon), 
			Spacer Box(size(10, 1)), 
			V Center Box(Text Box(text))
		)
	);
);


mini_modal_window("ERROR", "No data table open", "Error", "ErrorSmall");
-Jarmo

View solution in original post

David_Burnham
Super User (Alumni)

Re: Help with JSL Throw() not functioning as expected

Example of scanning for graph builder windows:

 

getGraphBuilderWindows = function({},{default local},
	
	lst = {};

	winList = getWindowList();
	for each({win},winList,
		winTitle = win << getWindowTitle;
		if (contains(winTitle,"Graph Builder"),
			insertinto(lst,win)
		)
	);
	return(lst);

	
);

lstGBWindows = getGraphBuilderWindows();
-Dave

View solution in original post

5 REPLIES 5
jthi
Super User

Re: Help with JSL Throw() not functioning as expected

Have you checked if there is any prints in JMP Log? The Throw might trigger but there just is no "error window". At least when I work with addins I use custom error modal window because Throw doesn't create error window like when run as a script.

Modal Dialogs has fairly simple alert function you could use instead of Throw (you can also throw but use modal window to show the error to user).

 

Edit:

Found one function I have used for info modal windows:

Names Default To Here(1);


mini_modal_window = function({title, text, text_icon = "BlankIndex", window_icon = "NewApplication"}, {Default Local},
	New Window(title, <<modal, << show toolbars(0), << show menu(0), << Set Window Icon(window_icon),
		H List Box(
			Icon Box(text_icon), 
			Spacer Box(size(10, 1)), 
			V Center Box(Text Box(text))
		)
	);
);


mini_modal_window("ERROR", "No data table open", "Error", "ErrorSmall");
-Jarmo
David_Burnham
Super User (Alumni)

Re: Help with JSL Throw() not functioning as expected

Try putting diagnostics in your code.

 

I put 

 

show ( Current Report() );

before your test, and it reported this:

 

Current Report() = DisplayBox[HeadBox];

Not empty.

-Dave
David_Burnham
Super User (Alumni)

Re: Help with JSL Throw() not functioning as expected

Also please realise that CurrentReport will look for any open window, including the ones you are creating.  You'll need to inspect the display tree ( e.g. OutlineBox(1) ) to identify a window as Graph Builder, and if you have opened other windows it may not be current, so perhaps search through a list of open windows.

-Dave
David_Burnham
Super User (Alumni)

Re: Help with JSL Throw() not functioning as expected

Example of scanning for graph builder windows:

 

getGraphBuilderWindows = function({},{default local},
	
	lst = {};

	winList = getWindowList();
	for each({win},winList,
		winTitle = win << getWindowTitle;
		if (contains(winTitle,"Graph Builder"),
			insertinto(lst,win)
		)
	);
	return(lst);

	
);

lstGBWindows = getGraphBuilderWindows();
-Dave
SDF1
Super User

Re: Help with JSL Throw() not functioning as expected

Hi @jthi and @David_Burnham ,

 

  Thank you both for your feedback and ideas. I like the mini modal window, it came in handy when testing to see if ANY Graph Builder was open.

 

  I decided to change things up and totally rewrote the code. It now does what I want, but it also keeps track through associative arrays which graph builder instance is for which project. With data tables, even with multiple open, it doesn't have a problem distinguishing between the different instances of Graph builder, even within a single data table, but since projects have multiple tabs, I had to make sure the assignment of the grab builder scriptable object was associated with the correct project. I was pretty happy to be able to use AAs and have them help me out, too! The new code also changes the first window depending on if you only have data tables (or projects) open or both.

 

  This was a nice little endeavor and I enjoyed working on it. After testing it some more, I will share with my organization. Below is the code if you're interested. I couldn't figure out how to get the For Each() to work when going through all possible projects and then through all windows within a project, so I did For() loops instead.

 

Thanks!,

DS

//JSL to add diagonal line and automatically resize to desired size
//Written by SDF1 with help/input from jthi, txnelson, Craige_Hales, David_Burnham, and Mark_Bailey

Names Default To Here( 1 );
Clear Symbols();

lb_width = 80;

Lines_n = 6;

mmw = Function( {title, text, text_icon = "BlankIndex", window_icon = "NewApplication"},
	{Default Local},
	New Window( title,
		<<modal,
		<<show toolbars( 0 ),
		<<Show Menu( 0 ),
		<<Set Window Icon( window_icon ),
		H List Box( Icon Box( text_icon ), Spacer Box( size( 10, 1 ) ), V Center Box( Text Box( text ) ) )
	)
);

getDTGraphBuilderWindows = Function( {},
	{default local}, 
	
	lst = {};

	winList = Get Window List( Type( "Reports" ) );
	For Each( {win}, winList,
		winTitle = win << get Window Title;
		If( Contains( winTitle, "Graph Builder" ),
			Insert Into( lst, win )
		);
	);
	Return( lst );
	
);

getPRJGraphBuilderWindows = Function( {},
	{default local}, 
	
	prjlst = {};
	prjGBlist = {};
	prj_list = Get Project List();
	prjTitle = prj_list << Get Window Title;
	For( i = 1, i <= N Items( prj_list ), i++,
		prjTitle[i] = prj_list[i] << Get Window Title;
		prjwinList = Get Window List( Project( prjTitle[i] ) );
		prjGBwinTitle = prjwinList << Get Window Title;
		For( l = 1, l <= N Items( prjGBwinTitle ), l++,
			If( Contains( prjGBwinTitle[l], "Graph Builder" ),
				Insert Into( prjGBlist, prjGBwinTitle[l] );
				Insert Into( prjlst, prjTitle[i] );
			)
		);
		prjGBAA = Associative Array( prjGBlist, prjlst );
	);
	
	Return( prjGBAA );
	
);

RprtUpdate_Expr = Expr(
	
	If(
		N Items( dtGBedit ) == 1, gb = Get Window( dtGBedit[1] )[Outline Box( 1 )] << Get Scriptable Object,
		N Items( PrjGBedit ) == 1,
			ActiveProj = PrjGBAA << Get Value( PrjGBedit[1] );
			gb = Get Window( Project( ActiveProj ), PrjGBedit[1] )[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(
	
	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 )
			)
		)
	);
	
);

Graphic_Expr = Expr(

	listDTGBWindows = getDTGraphBuilderWindows();
	dt_GB_list = listDTGBWindows << Get Window Title;
	
	PrjGBAA = getPRJGraphBuilderWindows();
	
	If( Is Missing( PrjGBAA ) != 1,
		ProjGBList = PrjGBAA << Get Keys; //GB graphs
		Projs = PrjGBAA << Get Values; //Project name
	);
	
	If(
		N Items( dt_GB_list ) == 0 & Is Empty( ProjGBList ) == 1,
			mmw( "ERROR", "No Graph Builder Open, Please Create a Graph.", "Error", "ErrorSmall" ), 
		
		N Items( dt_GB_list ) != 0 & Is Empty( ProjGBList ) == 1,
			GraphicWin = New Window( "Location of graphic",
				<<Return Result,
				<<On Validate,
				Outline Box( "Please Select the Graph Builder Graphic to Modify", <<Set Font Size( 12 ) ),
				Lineup Box( N Col( 3 ), Spacing( 4, 4 ),
					Panel Box( "Data Table Graphs",
						dtGB = List Box( dt_GB_list, width( <<Set Auto Stretching( 1, 0 ) ), nlines( Lines_n ), Max Selected( 1 ) )
					),
					Panel Box( "Actions",
						V List Box(
							Button Box( "OK",
								dtGBedit = dtGB << Get Selected;
								GraphicWin << Close Window;
								SquarifyWin_Expr;
							),
							Spacer Box( <<Set Auto Stretching( 0, 1 ) ),
							Button Box( "Cancel", GraphicWin << Close Window )
						)
					)
				)
			), 
	
		N Items( dt_GB_list ) != 0 & Is Empty( ProjGBList ) != 1,
			GraphicWin = New Window( "Location of graphic",
				<<Return Result,
				<<On Validate,
				Outline Box( "Please Select the Graph Builder Graphic to Modify", <<Set Font Size( 12 ) ),
				Lineup Box( N Col( 3 ), Spacing( 4, 4 ),
					Panel Box( "Data Table Graphs",
						dtGB = List Box(
							dt_GB_list,
							width( <<Set Auto Stretching( 1, 0 ) ),
							nlines( Lines_n ),
							Max Selected( 1 ),
							<<Set Script( PrjGB << Clear Selection )
						)
					),
					Panel Box( "Project Graphs",
						PrjGB = List Box(
							ProjGBList,
							width( <<Set Auto Stretching( 1, 0 ) ),
							nlines( Lines_n ),
							Max Selected( 1 ),
							<<Set Script( dtGB << Clear Selection )
						)
					),
					Panel Box( "Actions",
						V List Box(
							Button Box( "OK",
								If(
									N Items( dtGB << Get Selected ) == 1,
										dtGBedit = dtGB << Get Selected;
										GraphicWin << Close Window;
										SquarifyWin_Expr;,
									N Items( PrjGB << Get Selected ) == 1,
										PrjGBedit = PrjGB << Get Selected;
										GraphicWin << Close Window;
										SquarifyWin_Expr;
								)
							),
							Spacer Box( <<Set Auto Stretching( 0, 1 ) ),
							Button Box( "Cancel", GraphicWin << Close Window )
						)
					)
				)
			), 
			
		N Items( dt_GB_list ) == 0 & Is Empty( ProjGBList ) != 1,
			GraphicWin = New Window( "Location of graphic",
				<<Return Result,
				<<On Validate,
				Outline Box( "Please Select the Graph Builder Graphic to Modify", <<Set Font Size( 12 ) ),
				Lineup Box( N Col( 3 ), Spacing( 4, 4 ),
					Panel Box( "Project Graphs",
						PrjGB = List Box( ProjGBList, width( <<Set Auto Stretching( 1, 0 ) ), nlines( Lines_n ), Max Selected( 1 ), )
					),
					Panel Box( "Actions",
						V List Box(
							Button Box( "OK",
								PrjGBedit = PrjGB << Get Selected;
								GraphicWin << Close Window;
								SquarifyWin_Expr;
							),
							Spacer Box( <<Set Auto Stretching( 0, 1 ) ),
							Button Box( "Cancel", GraphicWin << Close Window )
						)
					)
				)
			)
	);	
	
);
	

Graphic_Expr;