I am trying to Create a pair of scripts, the first would save column names and formulas into a list and the second would bring those in thru use of namespace and apply them to another data table. I believe I have the basic namespace concept handled, but am having issues apply the properties. Any help would be much appreciated.
Script 1:
clear symbols(); //for debug
Names Default to Here(1); //namespace declaration,create variables in local scope only
ns = New Namespace("outer");
dt = Current data table();
if(isEmpty(dt),
try(dt = Open(), Throw("No data table found"))
);
nc = nCol( dt );
ns:names = dt << Get Column Names();// get column names
print(ns:names);
ns:formulaList={};
For( i = 1, i < N Items(ns:names), i++,
col = Column(i);
ns:formulaList[i] = col << get Property( "Formula");
);
print (ns:formulaList);
ns <<LOCK></LOCK>
Output:
{Col1, umn 2, Con 4, Column}
{Empty(), :Col1 + 8, :umn 2 * 3}
Script 2:
Clear Symbols(); //for debug
Names Default to Here(1); //namespace declaration,create variables in local scope only
ms=namespace("outer");
dt = Current Data Table();
If( Is Empty( dt ),
Try( dt = Open(), Throw( "No data table found" ) )
);
colSize = N Col( dt );
ListSize = N Items(ms:names);
For( i = 1, i < ListSize + 1, i++,
if(i > colSize, New Column( "temp" ));//create columns to accomidate list size
print(ms:names[i]);
Column(i) << Set NAME(ms:names[i]);//set column names
//col << Formula( Eval(ms:formulaList[i]) );//set column formulas
);
print(ms:formulaList);
//ms << Delete;
Output:
Col1
umn 2
Con 4
Column
{Empty(), :Col1 + 8, :umn 2 * 3}
The two main issues, the column names in second data table do not take on the new names, and if uncommented col << Formula breaks. Have tried many different ways but have yet to have success with getting either to work.
*Edit- added List/Column size check to second script
*Solved first question, see answer below.
The question now, is there a specific "type" Formula or Set Formula is expecting to enable it to work?
Thanks! Good JMP exampIes are hard to find. Seems to me the scripting guide lacks most of the practical examples for what im using it for. I have to check into some of those functions to get a full understand how this is working, but it is much easier with the complete picture you provided.
Here is a proposal to create columns, all properties, names, formulas, but no values.
The attached script uses colref << get script, and demonstrates the script using Big Class.jmp
The solution the the Column naming issue was a matter of "type"...
Solution in Script 1:
ns:names = dt << Get Column Names("String");// get column names