cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
  • New JMP features coming to desktops everywhere this September. Sign up to learn more at jmp.com/launch.
Choose Language Hide Translation Bar
shampton82
Level VII

Script for combining data table scripts with data from multiple files and saving into on JSL file

Hey everyone!

Okay after trying for way to long I am stuck on how to get this code to work.  I am trying to make a script that will allow a user to select from a list of open files, and for each file selected the code will copy the data table scripts and then paste them all into a single JSL file that I can then run at a later time and will open all the data tables again.  Basically like a way to pack a bunch of data tables into a single file (without having to ZIP them) so it is easier to store more complex analysis. This code does most of what I want but I can't get the table scripts to save to a JSL file, they keep wanting to open a copy of the files.

 

Names Default To Here(1);


nw = new window("Trial",show menu(0),
	vlistbox(
			hlistbox(
				panelbox("Open data tables",
					lb = listbox(get data table list ());
					),
				panelbox("Data tables to save into one script file",
					lb2 = listbox();
					),
					
			),
			buttonbox("press to select tables",dtla=lb << Get Selected;lb2 << Append( dtla );  ),
			buttonbox("press to remove tables",lb2 << Remove Selected();  ),
			panelbox("what is the file name?",
					teb1=Texteditbox();
					),
			buttonbox("press to save",
				dtlb=lb2 << Get items;
				fn=teb1 << Get Text();

				list_of_table_scripts={};

				For( i = 1, i <= N Items( dtlb ), i++,
						y = datatable(dtlb[i]) << Get Script With Data Table();

						insertinto(list_of_table_scripts,y);
					);
				
				Save Text File( "$desktop\"||fn||".jsl", y );

				nw<< Close Window;
				)
				



			  )
			
	);
	
teb1<< Set Width( 200 );

Thanks for any guidance!!

 

Steve

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Script for combining data table scripts with data from multiple files and saving into on JSL file

I wouldn't suggest saving data table as a script unless it is very small as the script size can quickly get massive. But if you really want to do this, you could use something like this

Names Default To Here(1);

dt1 = Open("$SAMPLE_DATA/Big Class.jmp");
dt2 = Open("$SAMPLE_DATA/Semiconductor Capability.jmp");

tables = Get Data Table List() << get name;

tablescripts = {};

For Each({tablename}, tables,
	s = DataTable(tablename) << Get Script;
	Insert Into(tablescripts, Char(Name Expr(s)));
);

Save Text File("$DOWNLOADS/demo.jsl", Concat Items(tablescripts, ";"));
-Jarmo

View solution in original post

5 REPLIES 5
jthi
Super User

Re: Script for combining data table scripts with data from multiple files and saving into on JSL file

I wouldn't suggest saving data table as a script unless it is very small as the script size can quickly get massive. But if you really want to do this, you could use something like this

Names Default To Here(1);

dt1 = Open("$SAMPLE_DATA/Big Class.jmp");
dt2 = Open("$SAMPLE_DATA/Semiconductor Capability.jmp");

tables = Get Data Table List() << get name;

tablescripts = {};

For Each({tablename}, tables,
	s = DataTable(tablename) << Get Script;
	Insert Into(tablescripts, Char(Name Expr(s)));
);

Save Text File("$DOWNLOADS/demo.jsl", Concat Items(tablescripts, ";"));
-Jarmo
jthi
Super User

Re: Script for combining data table scripts with data from multiple files and saving into on JSL file

Depending on how you would be using the tables later, you could collect either to JMP Project or to a zip file (both can be done with JSL). You might have to create a separate table loader script if you go this route unless you wish to use the files from JMP Project. I don't personally like their implementation at all so I tend to avoid them, but I have used them from time to time to package JMP files for archiving purposes. 

-Jarmo
shampton82
Level VII

Re: Script for combining data table scripts with data from multiple files and saving into on JSL file

@jthi , what would be the JSL for saving to a ZIP file?  I don't see anything in the scripting index.

jthi
Super User

Re: Script for combining data table scripts with data from multiple files and saving into on JSL file

I think you have to save your tables temporarily so you can load them as blobs

Names Default To Here(1); 

dt = Open("$SAMPLE_DATA/Big Class.jmp");

dt << Save("$TEMP\blob.jmp"); // save jmp table to load it as a blob
Close(dt, no save);
b = Load Text File("$TEMP\blob.jmp", blob);

za = Open("$TEMP\deleteMe.zip", zip);
za << Write("Big Class.jmp", b);

Delete File("$TEMP\blob.jmp");

There are quite a few improvements which could be added here.

-Jarmo
shampton82
Level VII

Re: Script for combining data table scripts with data from multiple files and saving into on JSL file

Thanks @jthi !

 

Added your code to mine and this works great!!  Thanks for the heads up on file size, I will have to keep an eye on that.

 

Names Default To Here(1);


nw = new window("Trial",show menu(0),
	vlistbox(
			hlistbox(
				panelbox("Open data tables",
					lb = listbox(get data table list ());
					),
				panelbox("Data tables to save into one script file",
					lb2 = listbox();
					),
					
			),
			buttonbox("press to select tables",dtla=lb << Get Selected;lb2 << Append( dtla );  ),
			buttonbox("press to remove tables",lb2 << Remove Selected();  ),
			panelbox("what is the file name?",
					teb1=Texteditbox();
					),
			buttonbox("press to save",
				dtlb=lb2 << Get items;
				fn=teb1 << Get Text();

				tablescripts = {};

				For Each({tablename}, dtlb,
					s = DataTable(tablename) << Get Script;
					Insert Into(tablescripts, Char(Name Expr(s)));
				);
				
				Save Text File( "$desktop\"||fn||".jsl", Concat Items(tablescripts, ";") );

				nw<< Close Window;
				)
				



			  )
			
	);
	
teb1<< Set Width( 200 );

Recommended Articles