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
wbwing
Level I

Scripts for multiple data windows

I am just getting started in JMP. I have a very basic current need. I need a quicker way to do a calculation and visualization of motor data files I'm recording. I am tired of doing it manually in excel everytime. A friend suggested JMP as a way to do it consisitently and quickly without having to get into Excel Macros. I downloaded the trial and am spending a couple days to see if it can do the job before convincing my boss to purchase. I'm very happy how quickly I was able to add calculated columns and graph the data. However I would really like to be able to load a data file (or series of files) and click a button that will add the columns and make the simple plot. I know the answer lies with scripts. From the graph builder I saved the script, but that script only shows up in the data window I already completed the task with. Everytime I open a new file, that script is no longer available. Furthermore, I'm pretty sure that script only makes the plot. How do I save a script to add the two columns I need when I open a new file?

 

 

9 REPLIES 9
gzmorgan0
Super User (Alumni)

Re: Scripts for multiple data windows

If you added files, they are not appearing.

ian_jmp
Staff

Re: Scripts for multiple data windows

Sounds like you might want to put everything into one script. If so, the example below should get you started (though it uses a CSV file).

 

Do 'File > New > New Script' to open a window, copy the code below, and paste it in. You can run it as it is (with 'Edit > Run Script'), and then adapt it to your case. Do 'File > Save' to save your new script file.

 

To learn a little about JSL, try 'Help > Books > Scripting Guide'.

Names Default To Here( 1 );

// Read in a sample csv file
dt = Open( "$SAMPLE_IMPORT_DATA/Book1.csv" );

// Add a formula column
dt << 
// To get this code, build your formula 'by hand', then do 'File > New > New Script',
// type the command 'columnRef << getScript', and then 'Edit > Run Script'. Then look
// immediately below or in 'Window > Log' to get the result. In this case, the command
// was: ':Formula << getScript'.
New Column( "Formula", Numeric, "Continuous", Formula( (:Name( "1" ) + :Name( "2" )) / :Name( "3" ) ) );

// Now use Graph Builder 'by hand', and get the JSL code it makes for you . . .
dt <<
// . . . and paste it here
Graph Builder(
	Size( 531, 452 ),
	Show Control Panel( 0 ),
	Variables( X( :Name( "1" ) ), Y( :Formula ) ),
	Elements( Points( X, Y, Legend( 6 ) ), Smoother( X, Y, Legend( 7 ) ) )
);

 

gzmorgan0
Super User (Alumni)

Re: Scripts for multiple data windows

@wbwing every scripting language requires a learning curve. @ian_jmp provided the basics: Open(), New Column() and GraphBuilder() for your scripting tasks. But you will need more.  My experience is that JSL, the JMP Scripting Language, has a less steep learning curve compared to other languages due to its extensive Scripting Index found in the main menu, its forgiving syntax, and Save Script options for its rich set of  graph and analysis platforms. However, JMP does not  provide a macro recorder, therefore it requires the scripter to learn the syntax (valid instructions) for point and click commands.

 

I have attached a simple script and 4 Excel files to play with. The script was created using JMP 14.  The screenshot below shows the interactive display window. It  has  two action buttons, Select File and Journal. The script starts the file search in your downloads directory. Good luck with your quest to have JMP available.

 

Script Display WindowScript Display Window

gzmorgan0
Super User (Alumni)

Re: Scripts for multiple data windows

The script did not get attached, see below.

wbwing
Level I

Re: Scripts for multiple data windows

This is also a very useful script. Thank you!

wbwing
Level I

Re: Scripts for multiple data windows

This is an excellent starting point. Thank you! So to use on a new csv (the data type of the files actually), I open the script in the editor, change the file name, and run the script from the editor?  It is also unclear to me how to set the import settings for the data file using the script. Like setting the delimiter (semicolons in this case) or the line for column labels and row the data begins.

 

Thank you!

ian_jmp
Staff

Re: Scripts for multiple data windows

If you have a bunch of .csv files of the same 'type' (meaning different contents, but laid out in the same way), use 'File > Open', navigate to one of them, then step though the import wizard 'by hand' making whatever choices you need to to read the contents correctly.

 

If all goes well you will get a JMP table. This table will have a 'Source' script, which is the JSL that tells JMP how to read the source file. If you right click on the little green 'run' arrow of this script, you can select 'Edit' to inspect the code. You can then cut and paste this into the code given above. To use it with a different file of the same type, just change the location of the file as defined in the 'Open()' command.

 

If you want to let a user pick thr file to process, look in 'Help > Scripting Index' for 'Pick File()'. 

 

gzmorgan0
Super User (Alumni)

Re: Scripts for multiple data windows

The attached script is a modification of the previous script:

  • gets the user import settings
  • set the import settings with semicolon field delimiters, etc
  • Pick File looks for CSV or text files. If you do not want txt remove ;txt from line 107
  • Uses Open(newfid, Invisible) since open will use the import settings preferences
  • changes on close to reset the users import settings
gzmorgan0
Super User (Alumni)

Re: Scripts for multiple data windows

BTW, the method @ian_jmp described is exactly what I do to get the import settings.