cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
shampton82
Level VII

JSL for how to copy and paste columns like you can with right clikcing a column

Hello 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

shampton82_0-1709413889899.png

 

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

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: JSL for how to copy and paste columns like you can with right clikcing a column

I 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});

 

-Jarmo

View solution in original post

hogi
Level XII

Re: JSL for how to copy and paste columns like you can with right clikcing a column

If it's just about the formula, you could use << get formula  - and then use the returned expression for creating the column in the second table:

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))))))

View solution in original post

9 REPLIES 9
hogi
Level XII

Re: JSL for how to copy and paste columns like you can with right clikcing a column

you 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()

 

 

shampton82
Level VII

Re: JSL for how to copy and paste columns like you can with right clikcing a column

Thanks 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

hogi
Level XII

Re: JSL for how to copy and paste columns like you can with right clikcing a column

Oh - this is more complicated than I thought.

 

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
jthi
Super User

Re: JSL for how to copy and paste columns like you can with right clikcing a column

I 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});

 

-Jarmo
hogi
Level XII

Re: JSL for how to copy and paste columns like you can with right clikcing a column

If it's just about the formula, you could use << get formula  - and then use the returned expression for creating the column in the second table:

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))))))
shampton82
Level VII

Re: JSL for how to copy and paste columns like you can with right clikcing a column

Those solutions both worked great.  Thanks @hogi and @jthi !

 

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.

 

Thanks again!

Steve

jthi
Super User

Re: JSL for how to copy and paste columns like you can with right clikcing a column

Copy 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});

 

-Jarmo

Re: JSL for how to copy and paste columns like you can with right clikcing a column

This 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?

jthi
Super User

Re: JSL for how to copy and paste columns like you can with right clikcing a column

What 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

-Jarmo