Choose Language Hide Translation Bar
Highlighted
aallman
Level III

Paste Table Script into Script

I am trying to save a script to my data table that will recreate a table I made previously. This is an add-in that is pretty extensive and involves opening/closing several different tables, creating summary tables, joining, updating and in the end the only data I will need for the reports is a simple 2 column table. I would like the users to be able to run this add-in one time, and if they accidentally close the resulting table, they will not have to run the add in again because there will be a script saved onto the original table that can recreate the final table and analysis window. 

Hopefully that makes sense!

The problem I am running into is that the final table is a summary of one of the many tables created during the add-in script. So if I use the <<Get Table Script function, the result is "Data Table that no longer exists"<<Summary......etc. I want to use the <<Copy table script function, because it actually saves the column names and the values in each cell, which is exactly what I want! However, I can't figure out how to do this within my add-in script. Copy Table Script does not return anything that can be saved as a variable or expression, only copies the information to the clipboard so that it can be pasted later. 

sum<<Delete scripts("Source");
script=sum<<copy table script;
	
dt<<New Script("Positions Table", script);

This is an example of one thing I have tried that didn't work. dt is the original table that I would like to save this script to. sum is the table I want to recreate within the script.

Is this even possible???

5 REPLIES 5
Highlighted
DS
DS
Level VI

Re: Paste Table Script into Script

Hi @aallman,

 

  I'm a little confused as to what exactly you are attempting to do, but it does sound somewhat similar to something I've done before, where I needed to Stack the source data table and then tabulate the output data table, but didn't want to have to re-script everything when I concatenated some new data to the source data table.

 

  Here's some example code of the where I have the Stack script written in the source dt.

Data Table( "Analysis" ) << Stack(
	columns(
		:X1,
		:X2,
		:X3,
		:X4,
		:X5,
		:X6
	),
	Source Label Column( "Test Apparatus" ),
	Stacked Data Column( "Data" )
);
Current Data Table() << Set Name( "Data Stack" ) <<
New Script(
	"Fit Y by X of Data by Source",
	Oneway(
		Y( :Data ),
		X( :Source ),
		Means( 1 ),
		Mean Diamonds( 1 ),
		By( :Test Apparatus )
	)
);
Data Table( "Data Stack" ) << New Column( "Date-Time",
	"Ordinal",
	Formula( :Date + :Time ),
	Format( "m/d/y h:m:s" )
);
Data Table( "Data Stack" ) << Group Scripts(
	"Run these after stacking",
	{"Tabulate by Lot (run after stacking)",
	"Tabulate by Apparatus (run after stacking)"}
);
Data Table( "Data Stack" ) << Move Script Group(
	"Run these after stacking",
	to last
);

  And it will carry-over the scripts to the newly stacked data table. I also have saved to the main dt the grouped scripts with the title "Run these after stacking", which also get carried over to the newly stacked data table.

 

  I imagine that you might be able to approach your problem in a similar fashion.

 

Good luck!,

DS

Highlighted
aallman
Level III

Re: Paste Table Script into Script

The result table from my script is essentially 2 columns: "Position" and "N Rows". This table is a summary of a table that was created during the long add-in, and not a summary of any columns in the main table. I cannot use any scripts that create tables using data from the current table (such as summary, stack, etc.). I need to somehow save the exact values in the result table to a script that I can save onto my main table. Something like this:

New Table( "Positions of'n-1 base'",
	Add Rows( 32 ),
	New Column( "Position",
		Numeric,
		"Nominal",
		Format( "Best", 10 ),
		Set Values(
			[1, 2, 3, 6, 8, 9, 11, 16, 18, 21, 23, 25, 26, 27, 28, 29, 30, 31, 32,
			34, 35, 36, 37, 38, 39, 40, 41, 46, 48, 63, 65, 68]
		)
	),
	New Column( "N Rows",
		Numeric,
		"Continuous",
		Format( "Fixed Dec", 20, 0 ),
		Set Values(
			[13, 52, 65, 52, 65, 65, 65, 52, 52, 65, 52, 31, 28, 23, 13, 21, 14, 17,
			9, 5, 4, 56, 1, 4, 5, 3, 55, 65, 65, 52, 13, 13]
		)
	)
)

But I can't figure out how to do that within my script. I don't know how to get this script, or save it to the main table. 

My plan was to immediately get the script when the result table first opened and save it to a new table script on my main table, that way if the result table was closed, it could be re-created using the main table script. 

Does that make more sense?

Highlighted
txnelson
Super User

Re: Paste Table Script into Script

I would just add the code to save the summary table as another script, and then in your main script just have it run the table script that recreates the summary table.

Jim
Highlighted
aallman
Level III

Re: Paste Table Script into Script

How do I save that script to my table?

Highlighted
txnelson
Super User

Re: Paste Table Script into Script

Here is a simple script showing one way to do this

names default to here(1);
dt=open("$SAMPLE_DATA\big class.jmp");

dtSum = dt << Summary(
	Group( :sex ),
	Mean( :height ),
	Freq( "None" ),
	Weight( "None" ),
	link to original data table(0)
);

Eval(
	Parse(
		Eval Insert( "\[dt << New Table Script("Summary Table Script", ^dtSum << get script^)]\" )
	)
);
Jim
Article Labels

    There are no labels assigned to this post.