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.
The Scripting Index

Learn how to use the Scripting Index to more easily learn JSL, either to write your own scripts or to customize the scripts JMP automatically produces for you.

 

Full Transcript (Automatically Generated)

View more...

Hi, everybody. Welcome to another edition of help, our review of the help resources in jmp and how to use effectively. I'm Ross, systems engineer. Today we're going to look at the scripting index, which is an excellent resource for getting the most out of jmp scripting language. If you know how to script or as we're going to see right now, even if you don't, for those who aren't familiar, jmp scripting language or JSL is a great way to extend jmps functionality, or to automate some of the things that you would normally do in jmps point and click interface. Right now we're going to look at an example of customizing a script that jmp produced for us automatically to get it to do something that we want.

 

So let's take a look at this data table. This is a data table that I have imported through the Excel import wizard. If you've used any of jmps import wizards before you have probably notice that there are tools where you can enter information to specify the formatting of that file, so that jmp imports it correctly. And this is one of the places where jmp produces automatically for you JSL scripts. Here we have the source script in the data table, I'll right click and select Edit so that we can take a look at what's in there. So you can see we have an open command where jmp is saying all I want to open this file, and then apply all of these settings that I had applied through the Excel wizards point and click interface.

 

So this is a great script that I can use to import other Excel files that I have that have the same formatting as the first one that I imported. I have one of those Excel files here on my desktop here. So you see I originally imported a file from December 2019. Here's one from January 2020. So I want to use this script to import the January 2020 file without having to go through all the pointing and clicking in the Excel import wizard. simple way I could do that. Maybe I'll actually just copy paste This filename into my script. Now I'm doing this in the table script. Normally, I would copy this out to a separate script window. But for our purposes here, this will be okay. So I've put that in.

 

And if I click run, jmp imports that January 2020 data file. So this is great I basically automated in a way Excel importing for myself. But this doesn't scale that well. You know, this requires me to copy paste or to type in which file I want to import. And I would rather have a solution where jmp presents me with a file open window where I can just point to the file that I want, and run the script on that. So that's something that I should be able to do in GLSL, but I don't know how so be a little help. Let's jmp to the scripting index to find some more information. So you'll find the scripting index under help scripting index. unpack what we're seeing here. In this middle column, we have a bunch of different commands. In JSL, and on the right we get a bunch of information about those commands.

 

On the left, we can view these commands by different categories, we want to operate on a file. So I could scroll on down to the file section here and see all the different commands that operate on files. I'm actually going to go ahead and just type something into our filter here to try to find what we're looking for. I want an open file window. So what I want to be presented with let's see what it pulls up. Well, I get a number of matches. Let me go ahead and filter down a little more to say Just give me the ones that operate on files. I got three matches, all right, open pick directory pic file, no pic file sounds like what I want to do.

 

So I'm gonna go ahead and take a look at that. Up at the top here on the right, we see the syntax for using pic file. Then we have a simple description here, where if you notice at the beginning says that it prompts the user with an open window returning the path name of the file. kind of sounds like what I want to do, but you know I want to learn more about how to use this pic file command before putting it Script down here, I have some example JSL code that I can run to see how this works. Let me go ahead and click this button to run the code that pops up this file open window that I want.

 

Let me go to the desktop and actually just point this right at that January 2020 file and click Choose and see what happens. So we're done. If we look down below, we can actually see what jmped did, it ran this pick file code. And this is what it produced. Here we have a text string that looks like where that file is living. And the file name corresponds pretty cleanly with what we actually want in our script. So it looks like PIP file is going to produce what we need. So it's good to go to pop into our script.

 

But before we do actually want to learn a little more about PIP file, I could go to the topic help, which will take you to the help documentation online. And if if we were to go there for the sake of time, we won't you'd learn that it says all of the arguments here all this extra stuff that maybe I don't totally understand it. is optional. Now one nice thing about the sample code that's put here in the scripting index is that it's editable, you can tweak it and then run that code in this little kind of sandbox to see what it does. In this case, I'm just going to delete all this stuff, maybe I don't even need it.

 

So let's just run a bear Peck file. So I'll run that again. And lo and behold, I get my file open window. I'll point to that file. I click Choose, it still returns what I'm looking for. So it looks like we're good to go. And because I'm feeling a little lazy, I don't even want to type the pic file out. I'm just going to go ahead and copy that and paste it right into my script. Now if you right JSL you probably think this looks a little funny. You know, leaving this semi colon here and all that but you know, this should work for our purposes.

 

So I'm going to go ahead and click Run. Alright, it's letting me point to file point to that January 2020. file, runs it through the Excel import wizard without us having to click anything and now I've imported a brand new file. So been able to use the scripting index to figure out what I needed to tweak this pre existing script just so that I can now Can I have a custom data importing tool. And I did that without writing a single line of code.

 

Instead, I was able to, you know, efficiently search the scripting index using the groupings and the filter to find this command that I wanted. I read a little bit more about it, I actually experimented with the code in our little sandbox down here. And then I was even able to actually just copy and paste some of this myself. So take home message JSL really powerful tool for extending jmps functionality and for automating your workflow and the scripting index, a powerful resource to help you get more out of JSL than you might otherwise. So that's it for help, Julian, back to you.

Comments

Hello Ross,

 

Thanks for this demonstration.

I look a way to add custom entries in the left windows of scripting index.

I want to offer to our users custom functions in a "new category" named "Company-name". Is it possible?


I found New Custom Function() function, but nothing to add a new category.

 

Thanks

Regards,

Sure, you can do that with New Custom Function(). 

 

/* Converts Meters to Kilometers */
Meter to Kilometer = New Custom Function( "Conversions", "Meter to Kilometer", Function( {x}, x / 1000 ) );
Meter to Kilometer << Description( "Converts Meters to Kilometers" );
Meter to Kilometer << Prototype( "Conversions:Meter to Kilometer(x)" );
Meter to Kilometer << Example( "Conversions:Meter to Kilometer(5000)" );
Meter to Kilometer << Formula Category("Conversions");
Meter to Kilometer << Scripting Index Category( "Conversions" );

Take a look at the Conversions Function Library add-in for more examples.

 

2020-06-04_09-44-32.050.png

 

 

 

 

This is perfect.

Thank you Jeff