Subscribe Bookmark RSS Feed

Copying properties between columns

Hi,

I need to script the creation of a copy of a column within a data table, together with all of its properties, including several that I've defined myself.  I see by right-clicking on any column in the table that there are "Copy Column Properties" and "Paste Column Properties" items included on the resulting drop-down menu, which do exactly what I want - so this is the functionality I need to reproduce in my script.

When I ask for any column's properties, I see there's a "Copy Column Properties" property listed.  There's no corresponding "Paste Column Properties" listed however, and either the "Add Column Properties" property doesn't perform this function or I'm trying to use it incorrectly.  What's the easiest way to do this, please?

Many thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

Try this:

dt=open("$SAMPLE_DATA\Big Class.jmp");

//add a custom property to ensure that the technique really copies custom properties

column(dt, "height")<<set property("my prop", "my value");

//get the script for the existing column

colscript=column(dt, "height")<<get script;

//change the name of the column that the column script will create

newcolscript=substitute(nameexpr(colscript), "height", "new height");

//evaluate the column script to create the new column

newcolscript;

-Jeff
2 REPLIES
Solution

Try this:

dt=open("$SAMPLE_DATA\Big Class.jmp");

//add a custom property to ensure that the technique really copies custom properties

column(dt, "height")<<set property("my prop", "my value");

//get the script for the existing column

colscript=column(dt, "height")<<get script;

//change the name of the column that the column script will create

newcolscript=substitute(nameexpr(colscript), "height", "new height");

//evaluate the column script to create the new column

newcolscript;

-Jeff

That's seriously ingenious!  Many thanks - it's exactly what I need.