Subscribe Bookmark RSS Feed

Make add-in from application? Get app path?

laisteve17

Occasional Contributor

Joined:

Jun 15, 2017

Is there a way to create an add-in from an application I have built? The application is fairly complex and all I would like to do is bundle it into an add-in. Additionally, this problem might be solved if someone can help me solve the following problem:

 

I built an application and have it in a folder (myApp/) and have scripts that I would like to include() from the source directory (myApp/src/). However, when I try to Get Default Directory() from within the app, it returns "/", which will not allow me to find the source folder if the application were run on a different computer. Is there a way to query the location of the app that is currently running? Alternatively, is there a way to bundle files into the application so I can reliably access my files (perhaps through a default path variable)?

 

My attempts to put the application into an add-in have failed. I can't run the app (.jmpappsource or .jmpapp) from the add-in. Also, since the application is fairly complex, I don't want to rebuild it in the add-in builder. Is there a way I could organize the app into an add-in? It would be great if JMP added an "Export application as add-in" or "Create add-in from application" feature.

3 REPLIES
nascif_jmp

Staff

Joined:

Jul 30, 2015

I had a similar issue when I tried to break down a JSL framework into multiple modules that would include each other. I solved it by adding the following code to the main module:

 

// Find the current location in the source tree for the given file
__getThisPath = Function({this_f}, {Default Local},
this_p = "";
ifl = Include File List();
For( ifli = 1, ifli <= NItems(ifl), ifli++,
a_path = ifl[ifli];
idx = contains(a_path, this_f);
If( idx > 0, this_p = Left(a_path, idx - 1); break()));
If( this_p == "", Throw("Unable to find path for " || this_f));
return(this_p));

 

Once I determined my script location in the file system, I was able to use it to find and include its dependencies:

 

// Use the current location in the source tree for this file
// in order to load its dependencies.
__INCLUDE = __getThisPath("timeit.jsl");
Set Path Variable("TI_HOME", __INCLUDE);
Include("$TI_HOME/../JSLhelpers/mfr.jsl");

 

 

ian_jmp

Staff

Joined:

Jun 23, 2011

Additionally, this paper from Predictum would show how others have managed this: Best Practices in JMP® Add-In Management

 
laisteve17

Occasional Contributor

Joined:

Jun 15, 2017

Thank you nascif_jmp for sharing your method and thank you ian_jmp for sharing the paper! Both were helpful but I settled for a different approach - restructuring my app/addin. Here are the steps I took to ensure that my application would find its include files, reliably, on different computers.

 

  1. Put all files/folders relevant to the application into a folder (I call it the app root directory, or root directory for short)
  2. Use a path variable for the app root directory and relative paths to refer to files and directories in the application.
    1. For example, a directory "$appRoot/" that contains a folder "src/" with my scripts and a "lib/" with images and icons. I refer to these as "$appRoot/src/" and "$appRoot/lib/"
  3. Save your app as a .jmpapp file, located somewhere under your app root directory or in one of its subdirectories (doesn't matter where as long as it's accessible via relative path from the root folder)
  4. Create an add-in and under additional files, add the app root directory (jmp will also import all of its files and subdirectories as well to be included in the add-in). These files will be located in the add-in's directory.
  5. Now you can locate all of your files by refering to the add-in's directory, which is in a default location on each computer. This location is retrieved by doing getPathVariable("ADDIN_HOME("My Add In Name")). Use this to find the files and directories you added in the previous step. In your add-in script, set the path variable to the add-in root directory:
    1. ADDIN_NAME = "My Add In Name";
    2. setPathVariable("appRoot", getPathVariable(evalInsert("ADDIN_HOME(^ADDIN_NAME^)")) || "App root directory/");
    3. Set other path variables relative to this root directory
  6. Run your application file from your add-in script by using open("$appRoot/pathToMyApp/myApp.jmpapp");
  7. To distribute your application, instead distribute the add-in that contains your application along with its necesary files