JSL for how to copy and paste columns like you can with right clikcing a columnHello everyone,
I was scouring the Scripting Index and I couldn't find any refence for how to script in the copy column and paste column options

The log will record the past portion but does not record the copy portion.
Looks like the paste portion is just creating a new formula with the same name and then pasting over the copied properties from the copied column (I'm trying to copy over multiple smoother formula columns from one data table to another)
// Paste columns
Data Table("UBS") << New Column("Smoother(UBS Temp)", Numeric, "Continuous", Format("Best", 12), Formula(So it looks like I'll have to loop through getting the column names, creating new columns in the new table, renaming them, and then copying and pasting the column properties.
Unless anyone has a better idea (which I'm sure there will be!)
Thanks for any input.
Steve
Automation and ScriptingRe: JSL for how to copy and paste columns like you can with right clikcing a columnWhat are you trying to do? If you just wish to copy character values (not the column properties) I would use Join or datatable subscripting. Also, make sure they column you are copying the values to is Character type
Re: JSL for how to copy and paste columns like you can with right clikcing a columnThis command doesn't seem to work for String values but I can't find another way to copy and paste characters from a column. Is there a different way to do this for characters?
Re: JSL for how to copy and paste columns like you can with right clikcing a columnCopy Column Properties + Paste Column Properties can be used for multiple columns, so it could be two lines if you want to use those (I most likely wouldn't and would use << get script and loop over the columns)
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Tiretread.jmp");
dt2 = New Table("test it",
New Column("T1", numeric, continuous),
New Column("T2", numeric, continuous),
New Column("T3", numeric, continuous),
Add Rows(10)
);
dt << Copy Column Properties({:MODULUS, :ELONG});
dt2 << Paste Column Properties({:T1, :T3});
</CODE></P>
<P> </P></LINGO-BODY><LINGO-SUB id="lingo-sub-729552" slang="en-US" mode="CREATE">Re: JSL for how to copy and paste columns like you can with right clikcing a column</LINGO-SUB><LINGO-BODY id="lingo-body-729552" slang="en-US" mode="CREATE"><P>Those solutions both worked great. Thanks <A href="https://community.jmp.com/t5/user/viewprofilepage/user-id/26800" target="_blank">@hogi</A> and <A href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366" target="_blank">@jthi</A> !</P><P> </P><P>I'll have to create a loop to work through my columns to get them transferred over so still not as elegant as if I had a single line item of JSL that mimicked the copy and one for the paste of the selected columns but at least I can get there now.</P><P> </P><P>Thanks again!<BR /><BR /></P><P>Steve</P></LINGO-BODY><LINGO-SUB id="lingo-sub-729541" slang="en-US" mode="CREATE">Re: JSL for how to copy and paste columns like you can with right clikcing a column</LINGO-SUB><LINGO-BODY id="lingo-body-729541" slang="en-US" mode="CREATE"><P>If it's just about the formula, you could use <FONT face="courier new,courier"><< get formula</FONT> - and then use the returned expression for creating the column in the second table:<BR /><BR /></P><PRE><CODE class=" language-jsl">Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
New Column( "A",
Format( "Best", 12 ),
Formula( :weight - :height )
);
myformula =:a << get formula;
dtnew = Open( "$SAMPLE_DATA/Big Class Families.jmp" );
Eval(Eval Expr(dt new << new column ("A", Formula(Expr(Name Expr(myformula))))))
Re: JSL for how to copy and paste columns like you can with right clikcing a columnI prefer using Send() function instead of using << in cases like this
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
newcol = dt << New Column("ABC", Numeric, Continuous, Formula(:height * :weight));
colscript = Column(dt, "ABC") << get script;
Eval(EvalExpr(
Send(dt, Expr(NameExpr(colscript)))
));
You can also use Copy/Paste column properties by scripting but I would use << get script as it is more clear what it should do and it won't mess with clipboard
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
newcol = dt << New Column("ABC", Numeric, Continuous, Formula(:height * :weight));
dt << Copy Column Properties({:ABC});
dt << New Column("ABCD");
dt << Paste Column Properties({:ABCD});
</CODE></P>
<P> </P></LINGO-BODY><LINGO-SUB id="lingo-sub-729458" slang="en-US" mode="CREATE">Re: JSL for how to copy and paste columns like you can with right clikcing a column</LINGO-SUB><LINGO-BODY id="lingo-body-729458" slang="en-US" mode="CREATE"><P>Oh - this is more complicated than I thought.</P><P> </P><PRE><CODE class=" language-jsl">my new table << myscript
doesn't work ...
So either one has to prepare the message via:
Eval (EvalExpr(dt << Expr(Name Expr(myscript))))
or
Eval(Substitute(Expr(dt << _message_), Expr(_message_), Name Expr(myscript)))
or switch the current data table before executing the script:
current data table( my new table);
myscript
Re: JSL for how to copy and paste columns like you can with right clikcing a columnThanks for the suggestion @hogi , probably a dumb question but what would the next step be? I tired using paste column properties once I had gotten the script from the reference column but that did not seem to work. Appreviate any insight into the next step!
Steve
Re: JSL for how to copy and paste columns like you can with right clikcing a columnyou can ask the column - same is possible for many more objects:
Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
New Column( "A",
Format( "Best", 12 ),
Formula( :weight - :height )
);
myscript = :A << get script()