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
BHarris
Level VI

How do I automatically add all columns to the Column Switcher in .jsl

I'm very much a beginner with JSL, I'm still learning --

 

I have many files that I need to review with Graph Builder, and each has a different number of columns.  The only constant is that I know I want column 1 as the Overlay, column 2 in the X-axis, column 3 in the Y-axis, and all the rest of the columns in the Column Switcher.  I'd love to have a script that would open up all the Graph Builder windows for all the currently-open data tables with these settings, but I don't know how to do that.  This is the closest I've gotten:

 

Graph Builder(
	Size( 1900, 1200 ),
	Variables(
		X( :Column(2) ),
		Y( :Column(3) ),
		Overlay( :Column(1) )
	),
	Elements( Points( X, Y, Legend( 10 ) ), Line( X, Y, Legend( 11 ) ) ),
	Column Switcher( :Column(3) ),
	SendToReport(
		Dispatch(
			{},
			"",
			ScaleBox
		)
	)
);

 

The two things I need help with:  (1) figure out how to set the Column Switcher to automatically load up all the columns in the data table without asking me, and (2) wrap this script in a loop that iterates over all the open data tables.

 

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How do I automatically add all columns to the Column Switcher in .jsl

The scripting is very straight forward, 

Names Default To Here( 1 );

// Loop across all data tables
For( i = 1, i <= N Table(), i++, 

	dt = Data Table( i );
	
	// Find all of the column names
	colList = dt << get column names( string );
	
	// Get the first 3 columns for special processing
	col1 = colList[1];
	col2 = colList[2];
	col3 = colList[3];

	// Remove first 2 from column switcher columns from the overall list
	Remove From( colList, 1, 2 );

	// Run the Graph Builder
	
	dt << Graph Builder(
		Size( 570, 621 ),
		Variables(
			X( As Column( col2 ) ),
			Y( As Column( col3 ) ),
			Overlay( As Column( col1 ) )
		),
		Elements( Points( X, Y, Legend( 10 ) ), Line( X, Y, Legend( 11 ) ) ),
		Column Switcher( col3, colList )
	);
);

 

Jim

View solution in original post

10 REPLIES 10
txnelson
Super User

Re: How do I automatically add all columns to the Column Switcher in .jsl

The scripting is very straight forward, 

Names Default To Here( 1 );

// Loop across all data tables
For( i = 1, i <= N Table(), i++, 

	dt = Data Table( i );
	
	// Find all of the column names
	colList = dt << get column names( string );
	
	// Get the first 3 columns for special processing
	col1 = colList[1];
	col2 = colList[2];
	col3 = colList[3];

	// Remove first 2 from column switcher columns from the overall list
	Remove From( colList, 1, 2 );

	// Run the Graph Builder
	
	dt << Graph Builder(
		Size( 570, 621 ),
		Variables(
			X( As Column( col2 ) ),
			Y( As Column( col3 ) ),
			Overlay( As Column( col1 ) )
		),
		Elements( Points( X, Y, Legend( 10 ) ), Line( X, Y, Legend( 11 ) ) ),
		Column Switcher( col3, colList )
	);
);

 

Jim
BHarris
Level VI

Re: How do I automatically add all columns to the Column Switcher in .jsl

Impressive! I kept trying to use "Column Switcher( :Column(3), :Column(all) )" and variations of that

Would any of these improvements to the script be possible? (1) Give it instead a folder full of txt files, and have it open them one at a time in Graph Builder, and when I close Graph Builder, it closes the corresponding Data Table file and opens the next one, (2) automatically move the focus to the column switcher so I can immediately begin arrowing through the variables without needing to click in the column switcher box, (3) full size the Graph Builder window on the screen when it opens.

JMP is quickly becoming my favorite piece of software.
txnelson
Super User

Re: How do I automatically add all columns to the Column Switcher in .jsl

All of what you suggest is doable in JMP.

You can use "Files in Directory()"  to get the file list, and then loop through them.

You can attach an "On Close()" function to the Graph Builder object, which will close the current data table, and then go get the next file from your list of files from the "Files in Directory()" list.

Examples and description are in the Scripting Index

     Help==>Scripting Index

Jim
BHarris
Level VI

Re: How do I automatically add all columns to the Column Switcher in .jsl

Thanks!
How about #2 in my list? (I think I can figure out #3...)
txnelson
Super User

Re: How do I automatically add all columns to the Column Switcher in .jsl

I do not know of a way to do the second request.
Jim
Jeff_Perkinson
Community Manager Community Manager

Re: How do I automatically add all columns to the Column Switcher in .jsl

I can't find a way either but a few presses of the tab key will shift the focus to the list of columns in the column switcher.

 

TabToColumnSwitcher.gif

-Jeff
BHarris
Level VI

Re: How do I automatically add all columns to the Column Switcher in .jsl

@txnelson -- I just spent about 3 hours with the Scripting Index and Scripting Guide trying to make this work, but couldn't figure out how to make the "on close()" function open the next file.  Here's what I thought *should* work, but doesn't.

 

(Reminder, the goal is to step through these files one at a time, bringing up a Graph Builder window and letting me evaluate the file, then when I close the Graph Builder window, it should close the data table and open up the next file and plot it.)

 

This script is called "jmp_reg_4.jsl" and is on my Desktop:

Names Default To Here( 0 );  // <-- trying to use globals so the file list will be maintained between invocations

/*
All of what you suggest is doable in JMP.
You can use "Files in Directory()"  to get the file list, and then loop through them.
You can attach an "On Close()" function to the Graph Builder object, which will close the current data table, and then go get the next file from your list of files from the "Files in Directory()" list.
Examples and description are in the Scripting Index
     Help==>Scripting Index
*/   


If( Not( As Global( "flist" ) ),
	jmpDir = Pick Directory( "Select the jmp directory." );
	flist = Files In Directory( jmpDir );
);

dt = Open( jmpDir || "/" || flist[1] );
Remove( flist, 1 );

colList = dt << get column names( string );
col1 = colList[1];
col2 = colList[2];
col3 = colList[3];
Remove From( colList, 1, 2 );
gb = dt << Graph Builder(
	size( 800, 600 ),
	Variables( X( As Column( col2 ) ), Y( As Column( col3 ) ), Overlay( As Column( col1 ) ) ),
	Elements( Points( X, Y, Legend( 10 ) ), Line( X, Y, Legend( 11 ) ) )
);
cs = gb << Column Switcher( col3, colList );
gb << on close(
	Close( dt, nosave );
	run script( "/Users/bh/Desktop/jmp_reg_4.jsl" );
);

I thought I was creating a global list of files to examine, and then at every invocation, if I still have elements in the "flist" (file-list) variable, then we simply grab the next one and load it and plot it.  But it's not working as I expect:  when I close the graph builder window, it correctly closes the data table, but then does nothing else.

BHarris
Level VI

Re: How do I automatically add all columns to the Column Switcher in .jsl

I figured it out.  I really wish JMP had a terminal sometimes...

 

If anyone else finds themselves here looking for this same solution, please reply and I'll share what I ended up with.

txnelson
Super User

Re: How do I automatically add all columns to the Column Switcher in .jsl

@BHarris It should would be nice if you could add your solution to this discussion, so it can be available to the whole Discussion Community.  

Jim