JMP add-ins are great additions to JMP core capabilities, and sometimes, you may find yourself needing to automate add-in creation with JSL. I worked with automated add-in creation when building my JMP add-in, the JMP to R Custom Add-In Builder. Here’s a nifty JSL trick for auto-creation of add-ins.
The code in this tutorial is adapted from a wonderful script written by @Justin_Chilton, who built the Custom Add-In Builder.
A JMP add-in (.jmpaddin) is a Zip file (.zip). The three minimum components of a JMP add-in are the addin.def and addin.jmpcust files, as well as the JSL script that will run when the add-in is in use. You may add additional files as you would like—for example, other JSL scripts, JMP tables, PDF or Word documents (commonly used for documentation), and pictures (often used for the add-in thumbnail).
In the following script excerpts, anything customizable is in capital letters (e.g. YOUR_ADDIN_NAME).
First, create the string that is used in the addin.def file. You will need your add-in name and ID. The name is what will be displayed on the add-in menu, and the ID is a unique identifier for the add-in, commonly seen in the format com.companyname.username.addinname.
//create string for addin.def file
addinDefString = "id=com.YOUR_COMPANY.YOUR_ID.YOUR_ADDIN_NAME
name=YOUR ADDIN NAME
supportJmpSE=0";
If you know your add-in is only supported on Windows or Mac, respectively, then you should add a line at the end of this string with either:
"host=Win"
Or
“host=Mac”
Next, create the string for your addin.jmpcust file:
addinjmpcustString = "\[<!-- JMP Add-In Builder created --><jm:menu_and_toolbar_customizations xmlns:jm="http://www.jmp.com/ns/menu" version="3">
<jm:insert_in_main_menu>
<jm:insert_in_menu>
<jm:name>Add-Ins</jm:name>
<jm:insert_after>
<jm:name></jm:name>
<jm:command>
<jm:name>YOUR ADDIN NAME</jm:name>
<jm:caption>Your Addin Name</jm:caption>
<jm:action type="path">$ADDIN_HOME(com.YOUR_COMPANY.YOUR_ID.YOUR_ADDIN_NAME)\YOUR_SCRIPT.jsl</jm:action>
<jm:icon type="none"></jm:icon>
</jm:command>
</jm:insert_after>
</jm:insert_in_menu>
</jm:insert_in_main_menu>
</jm:menu_and_toolbar_customizations>]\";
Then, in order to package your JSL script as a file, first load it as a text file:
addinScript = Load Text File("$SOME_PATH\YOUR_ADDIN_NAME.jsl");
Then, write all of your files to a zip archive:
//create a ZipArchive to write files to
za = Open("$DOCUMENTS\YOUR_ADDIN_NAME.jmpaddin", zip);
//write all necessary files to ZipArchive (which can also be binary blobs)
za << write("addin.def", addinDefString);
za << write("addin.jmpcust", addinjmpcustString);
za << write("YOUR_ADDIN_NAME.jsl", addinScript);
Finally, you can navigate to the folder you saved your files to and see your add-in, which can be installed upon double-click.
I also created a more “fill-in-the-blank” version of the script, in case you wanted to automate your add-in creation (if you need to create multiple and have variable names for your add-in name, files, directory, etc.), which is below.
The two variable names used in the script are addinName and dir, which are defined as follows:
addinName: the name of your add-in as a string, with spaces and title capitalization as you’d like it to appear in the add-in menu (e.g. “JMP to R Add-In Builder”)
dir: the directory under which you would like to save your add-in
addinDefStr = "id=com.YOUR_COMPANY.YOUR_ID" || addinName || "\!n name=" || addinName || "\!n supportJmpSE=0";
addinjmpcustStr = "\[<!-- JMP Add-In Builder created --><jm:menu_and_toolbar_customizations xmlns:jm="http://www.jmp.com/ns/menu" version="3">
<jm:insert_in_main_menu>
<jm:insert_in_menu>
<jm:name>Add-Ins</jm:name>
<jm:insert_after>
<jm:name></jm:name>
<jm:command>
<jm:name>]\" || uppercase(addinName) || "\[</jm:name>
<jm:caption>]\" || addinName || "\[</jm:caption>
<jm:action type="path">$ADDIN_HOME(com.jmp.]\" || lowercase(regex(addinName, "\s", "", globalreplace)) || "\[)\]\" || addinName || "\[.jsl</jm:action>
<jm:icon type="none"></jm:icon>
</jm:command>
</jm:insert_after>
</jm:insert_in_menu>
</jm:insert_in_main_menu>
</jm:menu_and_toolbar_customizations>]\";
addinScript = Load Text File("$SOME_PATH\YOUR_ADDIN_NAME.jsl");
//create a ZipArchive to write files to
za = Open(dir || "/" || addinName || ".jmpaddin", zip);
//write all necessary files to ZipArchive (which can also be binary blobs)
za << write("addin.def", addinDefStr);
za << write("addin.jmpcust", addinjmpcustStr);
za << write(addinName || ".jsl", addinScript);
Hope these scripts can help make your add-in creation projects smoother!