Can anyone think of a simple way of duplicating a selected column in a data table? Basically, I'd like to select the column, and get a "Copy Of" with all the attributes, values, etc. right next to the original, in a single menu item click. Doing it by adding, moving, setting types, copying values etc. is a pain. I suppose it could be scripted as an Add-In but I was hoping that there was a simpler way.
Thanks!
Try something like this. It supports selection and copying of multiple columns.
Names Default To Here( 1 );
dt = Current Data Table();
cols = dt << get selected columns;
For( i = 1, i <= N Items( cols ), i++,
dt << clear column selection;
colscr = cols[i] << getscript;
(Eval( Substitute( Name Expr( colscr ), Arg( Name Expr( colscr ), 1 ), "Copy of " || (cols[i] << get name) ) )) << set selected( 1 );
dt << move selected columns( After( cols[i] ) );
);
So I created this as an Add-In. The bottom part (commented out) was an attempt to copy Column Properties but it didn't work. (This was what I was trying to avoid, but I had a long meeting with nothing better to do...) I'd still be interested if there's something more elegant than this approach.
dt = Current Data Table();
selcol = dt << Get Selected Columns;
selcolname = dt:selcol << Get Name();
newcname = "Copy Of " || selcolname;
newc = dt << New Column( newcname );
newclist = dt:newc << Get Name(); //in case this is a second copy!
movestr = "dt << Move Selected Columns({\!"%newclist%\!"}, After(\!"%selcolname%\!") );";
eval insert into(movestr,"%");
movestrexpr = Parse(movestr);
movestrexpr;
For Each Row(dt:newc = dt:selcol);
/*proplist = dt:selcol << Get Properties List();
for(i=1, i < N Items(proplist), i ++,
currprop = Char(proplist);
gotpropstr = "gotprop = dt:selcol << Get Property(\!"%currprop%\!");";
eval insert into(gotpropstr,"%");
gotpropstrexpr = Parse(gotpropstr);
gotpropstrexpr;
setpropstr = "newc << Eval List(Set Property(\!"%currprop%\!", List(gotprop)));";
eval insert into(setpropstr,"%");
setpropstrexpr = Parse(setpropstr);
setpropstrexpr;
);
newcproplist = dt:newc << Get Properties List();
//Show Properties(dt:selcol);
*/
Try something like this. It supports selection and copying of multiple columns.
Names Default To Here( 1 );
dt = Current Data Table();
cols = dt << get selected columns;
For( i = 1, i <= N Items( cols ), i++,
dt << clear column selection;
colscr = cols[i] << getscript;
(Eval( Substitute( Name Expr( colscr ), Arg( Name Expr( colscr ), 1 ), "Copy of " || (cols[i] << get name) ) )) << set selected( 1 );
dt << move selected columns( After( cols[i] ) );
);
Thanks, getscript is exactly what I was missing in my scripting knowledge!