Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
DS
DS
Level VI

How to write a script to save a currently open report as a PDF

Hi All, I'm not new JMP, but relatively new to JSL. I'm trying to write a script to help automate some data analysis and output of said analysis.

 

I have a parent JSL script that I'm running that allows users to open files of interest for analysis and then perform a possible sequence of analyses, e.g. distributions, models fits, multivariate, bivariate fits, etc.

 

I am using a generic function in the script to ask the user to select from the current list of windows (data tables) on which to perform the analysis. The user would select a data table for performing, e.g. a multivariate analysis. I want to have this parent script also have a button script that offers them an option to then save a selected report (again calling the generic select window function). I am having a hard time taking the existing report window, e.g. multivariate analysis, and then sending that to a PDF. I have tried writing code to get the script from the report window and rerun that to send to a journal and save as a PDF, but this fails.

 

Below is my parent script:

Names Default To Here( 1 );
choose_data_table = Function( {},
	list = {};
	For( i = 1, i <= N Table(), i++,
		list[i] = Data Table( i ) << get name
	);
	win = New Window( "Select a data table",
		<<Modal,
		hb = H List Box(
			Panel Box( "Choose a data table",
				dt = List Box( list, max selected( 1 ), chosen = Data Table( (dt << get selected)[1] ) )
			),

		)
	);
);
New Window( "Data Workup",
	Button Box( "JMP?",
		Web( "C:\Program Files\SAS\JMP\14\Help\index.html" ),
		<<Style( "Underline" ),
		<<Horizontal Alignment( "Right" )
	),
	Text Box(
		"A script to help automate data analysis",
		<<Horizontal Alignment( "center" ),
		<<Set Wrap( 350 ),
		<<Set Font Size( 12 )
	),
	Text Box( "", <<Justify Text( "left" ), <<Set Wrap( 350 ) ),
	H List Box(
		Panel Box( "File Operations",
			V List Box(
				Button Box( "Open file", Open() ),
				Button Box( "Rename data table",
					choose_data_table;
					Wait( 1 );
					User_Input = New Window( "Enter new name",
						<<Modal,
						H List Box( Text Box( "New name:" ), rename = Text Edit Box( "", <<set width( 200 ) ), ),
						Text Box( "Click OK to save" ),
						Button Box( "OK", newname = rename << get text() ),

					);
					chosen << Set Name( newname );
				)
			)
		),
		Panel Box( "Analysis Operations",
			V List Box(
				Button Box( "Select distributions",
					choose_data_table;
					Distribution();
				),
				Button Box( "Graph builder",
					choose_data_table;
					Graph Builder( Variables, Elements( Points( Legend( 1 ) ) ) );
				),
				Button Box( "Fit Y by X",
					choose_data_table;
					Bivariate();
				),
				Button Box( "Fit model",
					choose_data_table;
					Fit Model();
				),
				Button Box( "Multivariate",
					choose_data_table;
					Multivariate();
				)
			)
		)
	)
) << Size Window( 300, 300 );

 

Here is the script I'm using to try and extract the data to a jrn and save as pdf:

Names Default To Here( 1 );
wlist = Get Window List() << Get Window Title();
choose_window = Function( {},
	win = New Window( "Select a Report",
		<<Modal,
		hb = H List Box(
			Panel Box( "Select a report window",
				tcf = List Box( wlist, Max Selected( 1 ), chosen = tcf << Get Selected() )
			), 

		)
	)
);
choose_window;
chosen[1] << SaveAs();

 

And here's the error I get:

Send Expects Scriptable Object in access or evaluation of 'Send' , chosen[1] << /*###*/SaveAs() /*###*/

 

I've tried many ways to get around this, but somehow I can't seem to get the JSL script to exectute a function allowing the user to select the report window of choice and have that then saved as a PDF (or PNG, or JPG, etc. -- as desired by the user).

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
gzmorgan0
Super User

Re: How to write a script to save a currently open report as a PDF

Try this:

Names Default To Here( 1 );
wlist = Get Window List() << Get Window Title();
choose_window = Function( {},
	win = New Window( "Select a Report",
		<<Modal,
		hb = H List Box(
			Panel Box( "Select a report window",
				tcf = List Box( wlist, Max Selected( 1 ), chosen = tcf << Get Selected() )
			), 

		)
	);
 chosen;	
);
chosen = choose_window();
w = window(chosen[1]);
w << journal;
//you might need to scale the report to fit in the pdf page
w << Set page setup( margins( 0.5, 1, 0.5, 1 ), scale( .9 ), portrait( 1 ), paper size( "Letter" ) );
w << save pdf("C:/temp/chosen_test.pdf")


View solution in original post

2 REPLIES 2
Highlighted
gzmorgan0
Super User

Re: How to write a script to save a currently open report as a PDF

Try this:

Names Default To Here( 1 );
wlist = Get Window List() << Get Window Title();
choose_window = Function( {},
	win = New Window( "Select a Report",
		<<Modal,
		hb = H List Box(
			Panel Box( "Select a report window",
				tcf = List Box( wlist, Max Selected( 1 ), chosen = tcf << Get Selected() )
			), 

		)
	);
 chosen;	
);
chosen = choose_window();
w = window(chosen[1]);
w << journal;
//you might need to scale the report to fit in the pdf page
w << Set page setup( margins( 0.5, 1, 0.5, 1 ), scale( .9 ), portrait( 1 ), paper size( "Letter" ) );
w << save pdf("C:/temp/chosen_test.pdf")


View solution in original post

Highlighted
DS
DS
Level VI

Re: How to write a script to save a currently open report as a PDF

Worked great, @gzmorgan0. Thank you!

 

I did modify the scaling factor based on some discussion in this thread: https://community.jmp.com/t5/Discussions/Scaling-to-fit-to-page-width/td-p/33952

 

Now, it will adjust the size of the report to fit the page width as needed, which is really nice.

 

Thanks for the quick help!

Article Labels

    There are no labels assigned to this post.