cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
martinschmid
Level II

How to save .csv-file as .jmp-file and exit JMP with JSL

I have a folder with 365 .csv-files. I want to convert each .csv-file into a .jmp-file and delete some columns in the .jmp-file, then save the .jmp-file with the name of the .csv-file and exit JMP. All this has to be done automatically with a JSL-Script.

I already have a batch-script, which starts a JSL-Script and hands one .csv-file to the JSL-Script. The JSL-Script then opens the .csv-file and deletes the columns i want to delete.

I have a problem, when it comes to saving the .jmp-file and quitting JMP with the JSL-Script in order for the batch-script to start with the next .csv-file to open with the JSL-Script.

The .jmp-file won't save and therefor JMP doesn't quit, so that my whole batch-process stops, because my batch-script waits for JMP to be closed.

I open the .csv-files according to the response of user "twaintwist" at the bottom of this discussion: Passing Parameters to JSL script

All my .csv-files + the batch-script + the .jsl-script are in the same folder.

This solution works fine for me, so here is my batch-script:

for %%f in (*.csv) do (

    echo fileName = "%%~nf.csv";>file.txt

    copy /y /b file.txt+myScript.jsl temp.jsl

    JMP temp.jsl

    timeout / t 5

    del %%~nf.csv

    timeout / t 5

    del file.txt

    timeout / t 5

    del temp.jsl

)

pause

My JSL-Script then opens the .csv-file handed over by the .bat-script, and deletes some columns. But after deleting the cloumns it seems like my JSL-Script just stops.

The .jmp-file won't save and JMP does not quit. As you can see in the Script I tried different methods to save and close the window with JSL.

So here is my JSL-Script:

doc = Open(fileName);

dt = Current Data Table();

// Turns off display updating to allow for quick updating of a data table.

dt << Begin Data Update;

ColList = {

     //#COLUMNS TO BE DELETED#

};

dt << Delete Columns(ColList);

dt << End Data Update;

nameLength = Length(fileName);

fielName = Left(fileName, nameLength - 3);

Name = fileName || "jmp";

dt<<save("C:\Users\MartinSchmid\Desktop\jsl_batch\" || Name);

doc<<save("C:\Users\MartinSchmid\Desktop\jsl_batch\" || Name);

wait(10);

Close (dt, nosave);

Close (doc, NoSave);

//doc << close window;

//dt<<close window();

//Close All(Data Tables, save(fileName+"jmp"));

Exit(nosave);

Quit(nosave);

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: How to save .csv-file as .jmp-file and exit JMP with JSL

Check the JSL log for messages.  closing dt and doc might be an issue; are they the same table?

Craige

View solution in original post

5 REPLIES 5
Craige_Hales
Super User

Re: How to save .csv-file as .jmp-file and exit JMP with JSL

Check the JSL log for messages.  closing dt and doc might be an issue; are they the same table?

Craige
martinschmid
Level II

Re: How to save .csv-file as .jmp-file and exit JMP with JSL

Thank You very much! Your solution solved my problem...

As a total beginner in JSL I didn't know there was something like a log.

As I checked the log i noticed that my delete columns function didn't work as properly as I thought, because I misstyped one of the column-names and so the function stopped.

Nevertheless closing dt and doc was also wrong, but that wasn't too big of a problem in the end.

Once again thank you for your help!

Craige_Hales
Super User

Re: How to save .csv-file as .jmp-file and exit JMP with JSL

Great, glad you got it working.

You could also do all of this in JSL without a .BAT file.  That might (or might not) simplify your overall process.  JSL has a FilesInDirectory function and powerful string manipulation functions that can build and validate filenames.  If your current solution is too slow because of waits and timeouts and repeatedly starting/stopping JMP, you might want to eliminate the .BAT file.

Craige
martinschmid
Level II

Re: How to save .csv-file as .jmp-file and exit JMP with JSL

Unfortunately this process belongs to a bigger system and I need to be able to schedule it with windows scheduler, so I will need the .BAT anyways, but thanks for reminding me that it could be done in JSL only ;-)

msharp
Super User (Alumni)

Re: How to save .csv-file as .jmp-file and exit JMP with JSL

You can schedule JSL scripts just as you can schedule .bat files.

Add a '//!' to the first line of your script OR change the .jsl to a .rpt and it will auto-run when opened.  Then just have your windows scheduler point to the JMP script instead of the batch file.

Just saying.