cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
marie_gaudard
Level III

Using a script, how do I set the text of a table script in a button box in a journal file?

Using a script, I need to construct a completely self-contained journal file with button boxes that reproduce data tables.  In the production application, there will be many headings (each representing a part), and each heading will have several button boxes beneath it, each showing a different data table associated with the part.  Because of the complex calculations that go into constructing the data tables, I am constructing them using functions.  My intent would be to distribute ONLY the journal file to users.

 

I have constructed a skeletal example using the Baltic.jmp sample data table. The function "SmallTables()" returns the table script as text.  But I can't find a way to enter that text in the script boxes for the button boxes in the journal file. Any help would be greatly appreciated.

 

SmallTables = Function( {k},
	dt = Open( "$Sample_Data/Baltic.jmp" );
	dt_Small = dt << Subset( Rows(), Columns( Column( k ) ), Output Table Name( "Small" ) );
	Close( dt, NoSave );
	tblScript = dt_Small << Get Script;
	result = Char( Name Expr( tblScript ) );
);

jrn = New Window( "Table Test", Outline Box( "Title" ) );

For( k = 1, k <= 5, k++,
	jrn << Append( BB = Button Box( "Small Table " || Char( k ), Set Script( SmallTables( k ) ) ) )
);
2 ACCEPTED SOLUTIONS

Accepted Solutions
gzmorgan0
Super User (Alumni)

Re: Using a script, how do I set the text of a table script in a button box in a journal file?

If you will be using one table, I wouldn't open and close it for each function call. I'd open the table, build the window, with the for loop then close the table.

 

Try this.

SmallTables = Function( {k},
	dt = Open( "$Sample_Data/Baltic.jmp" );
	dt_Small = dt << Subset( Rows(), Columns( Column( k ) ), Output Table Name( "Small" ), Invisible );
	Close( dt, NoSave );
	_xx = dt_Small << Get Table Script Names;
	dt_Small << Delete Scripts(_xx); 
	tblScript = dt_Small << Get Script;
	wait(0);
	Close( dt_Small , NoSave);
	NameExpr(tblScript)
);

jrn = New Window( "Table Test", Outline Box( "Title" ) );

For( k = 1, k <= 5, k++,
    _xx = SmallTables(k);
	Eval(Substitute(Expr(jrn << Append( BB = Button Box( "Small Table " || Char( k ), Set Script( _scr ) ) )),
	  Expr(_scr), NameExpr(_xx) ) )
);

View solution in original post

ih
Super User (Alumni) ih
Super User (Alumni)

Re: Using a script, how do I set the text of a table script in a button box in a journal file?

I use self-contained journal files for demos and training, making them easy to share. Links to close individual sections and to clean up everything keeps things moving.  The script below creates a basic example journal; once you run it, you should see a journal with links in it.  Right click on each and select Edit > Edit Script to see how they are constructed.  I use 'Copy Table Script' often to populate these.  Putting this codes in functions is a good idea, but be mindful of it looking more like black magic to beginning users who try to explore your journal.

 

journal.png

Note that I normally make journals interactively, not using a script like this.

names default to here(1);

//Open data tables temporarily so we can copy their scripts
dtIrisTemp = open("$Sample_Data/Iris.jmp");
dtBigClassTemp = open("$Sample_Data/Big Class.jmp");

//Use Eval(EvalExpr()) so the actual scripts for the data table are saved in
//the journal.
Eval( Eval Expr(
	journal = New Window( "A Journal", <<Journal,
		V List Box(
			Outline Box( "Distributions",
				Text Box( "JMP can show the distribution of data values."),
				H List Box(
					//Open the table or bring it forward if it is already open
					Button Box( "Iris Data", 
						Try( 
							dtIris << Bring Window to Front();
						,
							dtIris = expr( dtIrisTemp << Get Script() );
						)
						, << Underline Style(1)
					),
					//Button to close the table
					Button Box( "<< Close",
						Try(dtIris << Close Window)
						, << Underline Style(1)
					)
				),
				Button Box( "A Distribution",
					Try(dtIris << Distribution(
						Continuous Distribution( Column( :Sepal length ) ),
						Continuous Distribution( Column( :Sepal width ) )
					))
					, << Underline Style(1)
				)
			),
			Outline Box( "Graphs",
				Text Box( "JMP can make graphs."),
				H List Box(
					//Open the table or bring it forward if it is already open
					Button Box( "Big Class Data", 
						Try( 
							dtBigClass << Bring Window to Front();
						,
							dtBigClass = expr( dtBigClassTemp << Get Script() );
						)
						, << Underline Style(1)
					),
					//Button to close the table
					Button Box( "<< Close",
						Try(dtBigClass << Close Window)
						, << Underline Style(1)
					)
				),
				Button Box( "A Graph",
					Try(dtBigClass << Graph Builder(
						Show Control Panel( 0 ),
						Variables( X( :weight ), Y( :height ) ),
						Elements( Points( X, Y, Legend( 6 ) ) )
					))
					, << Underline Style(1)
				)
			),
			Button Box( "Clean Up - Close Everything",
				Try(
					dtIris << Close Window;
					dtBigClass << Close Window;
				)
				, << Underline Style(1)
			)
		)
	);
) );

dtIrisTemp << Close Window;
dtBigClassTemp << Close Window;

 

 

View solution in original post

7 REPLIES 7
marie_gaudard
Level III

Re: Using a script, how do I set the text of a table script in a button box in a journal file?

 
gzmorgan0
Super User (Alumni)

Re: Using a script, how do I set the text of a table script in a button box in a journal file?

If you will be using one table, I wouldn't open and close it for each function call. I'd open the table, build the window, with the for loop then close the table.

 

Try this.

SmallTables = Function( {k},
	dt = Open( "$Sample_Data/Baltic.jmp" );
	dt_Small = dt << Subset( Rows(), Columns( Column( k ) ), Output Table Name( "Small" ), Invisible );
	Close( dt, NoSave );
	_xx = dt_Small << Get Table Script Names;
	dt_Small << Delete Scripts(_xx); 
	tblScript = dt_Small << Get Script;
	wait(0);
	Close( dt_Small , NoSave);
	NameExpr(tblScript)
);

jrn = New Window( "Table Test", Outline Box( "Title" ) );

For( k = 1, k <= 5, k++,
    _xx = SmallTables(k);
	Eval(Substitute(Expr(jrn << Append( BB = Button Box( "Small Table " || Char( k ), Set Script( _scr ) ) )),
	  Expr(_scr), NameExpr(_xx) ) )
);
marie_gaudard
Level III

Re: Using a script, how do I set the text of a table script in a button box in a journal file?

Thank you so much!  That works perfectly in my "big" script.  I was fixated on the idea that the result of my function was a text representation of the script, and, as such, should be entered in the button box script dialog. I'm still unclear as to why that doesn't work, but using the Name Expr function and Substitute, as you demonstrated, works perfectly.

By the way, in my real-life application, the loop is required because I need to construct different tables.  I have a large number of parts, and the script constructs several data tables, with scripts, that are unique to each part.  That script  takes a little while to run, so it's great to be able to run that script to create a self-contained journal file.

Thank you again for setting me on the right path!

ih
Super User (Alumni) ih
Super User (Alumni)

Re: Using a script, how do I set the text of a table script in a button box in a journal file?

The trick is making sure the sub-expression is inserted before it is evaluated. This JSL Cookbook article might help:

 

Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute

marie_gaudard
Level III

Re: Using a script, how do I set the text of a table script in a button box in a journal file?

Thank you so much for the reference to that article!  It's a very clear explanation with nice examples.  It is very helpful.

ih
Super User (Alumni) ih
Super User (Alumni)

Re: Using a script, how do I set the text of a table script in a button box in a journal file?

I use self-contained journal files for demos and training, making them easy to share. Links to close individual sections and to clean up everything keeps things moving.  The script below creates a basic example journal; once you run it, you should see a journal with links in it.  Right click on each and select Edit > Edit Script to see how they are constructed.  I use 'Copy Table Script' often to populate these.  Putting this codes in functions is a good idea, but be mindful of it looking more like black magic to beginning users who try to explore your journal.

 

journal.png

Note that I normally make journals interactively, not using a script like this.

names default to here(1);

//Open data tables temporarily so we can copy their scripts
dtIrisTemp = open("$Sample_Data/Iris.jmp");
dtBigClassTemp = open("$Sample_Data/Big Class.jmp");

//Use Eval(EvalExpr()) so the actual scripts for the data table are saved in
//the journal.
Eval( Eval Expr(
	journal = New Window( "A Journal", <<Journal,
		V List Box(
			Outline Box( "Distributions",
				Text Box( "JMP can show the distribution of data values."),
				H List Box(
					//Open the table or bring it forward if it is already open
					Button Box( "Iris Data", 
						Try( 
							dtIris << Bring Window to Front();
						,
							dtIris = expr( dtIrisTemp << Get Script() );
						)
						, << Underline Style(1)
					),
					//Button to close the table
					Button Box( "<< Close",
						Try(dtIris << Close Window)
						, << Underline Style(1)
					)
				),
				Button Box( "A Distribution",
					Try(dtIris << Distribution(
						Continuous Distribution( Column( :Sepal length ) ),
						Continuous Distribution( Column( :Sepal width ) )
					))
					, << Underline Style(1)
				)
			),
			Outline Box( "Graphs",
				Text Box( "JMP can make graphs."),
				H List Box(
					//Open the table or bring it forward if it is already open
					Button Box( "Big Class Data", 
						Try( 
							dtBigClass << Bring Window to Front();
						,
							dtBigClass = expr( dtBigClassTemp << Get Script() );
						)
						, << Underline Style(1)
					),
					//Button to close the table
					Button Box( "<< Close",
						Try(dtBigClass << Close Window)
						, << Underline Style(1)
					)
				),
				Button Box( "A Graph",
					Try(dtBigClass << Graph Builder(
						Show Control Panel( 0 ),
						Variables( X( :weight ), Y( :height ) ),
						Elements( Points( X, Y, Legend( 6 ) ) )
					))
					, << Underline Style(1)
				)
			),
			Button Box( "Clean Up - Close Everything",
				Try(
					dtIris << Close Window;
					dtBigClass << Close Window;
				)
				, << Underline Style(1)
			)
		)
	);
) );

dtIrisTemp << Close Window;
dtBigClassTemp << Close Window;

 

 

marie_gaudard
Level III

Re: Using a script, how do I set the text of a table script in a button box in a journal file?

What a nice example!  In my project, though, I need to construct hundreds of data tables, several for each of many parts.  This is why I am using functions to construct the data tables (hopefully no beginning user will ever see that script!). I'm afraid that your suggestion would result in too many windows being open at once. But, for a manageable number of data tables, your concept is very nice!  I am sure that I'll have occasion to use it.

Thank you so much for your help.