The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Difficulty with multiple ascii import script
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

SethM

USA
1 Posts

Posted - 01/31/2022 :  1:50:32 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello,

I am attempting to import 50 ascii files into a single worksheet alongside a script that will add 2 additional columns as well as changing their long name and units.

The script works when I import a single ascii file, however when I do a multiple ascii import, the new file overwrites the script created columns so instead of getting 2 columns per file, I'm getting 2 columns after the entire import.

IMPORT OPTIONS
First file: Replace existing data
Multiple file: Start new columns

Script (after each file is imported):
wks.ncols = wks.ncols + 2; //add 2 new columns to end of worksheet
wks.col = wks.ncols - 1; //select 1st new column
wks.col.lname$ = "Current Density";
wks.col.unit$ = "mA/cm^2";
wks.col = wks.ncols; //select last new column
wks.col.lname$ = "Log Current Density";
wks.col.unit$ = "mA/cm^2";

Ideally I'd import a 3 column ascii, add 2 new columns, rename and change units.
Then I'd import a 2nd 3 column ascii, add 2 new columns, etc.

In sum, the files imported after the first are overwriting my script created columns, OR my script isn't creating the columns until the entire import is completed.

YimingChen

1664 Posts

Posted - 02/02/2022 :  3:24:28 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can execute the Python code below in Origin to import multiple files with extra columns for each import. To run a piece of Python code in Origin Code Builder, please check this page:
https://www.originlab.com/doc/python/Running_Python_Code#From_Code_Builder


import originpro as op
import pandas as pd

op.lt_exec('fdlog.reset();fdlog.usegroup(ASCII);fdlog.multiopen();')
n = op.lt_int('FDlog.MultiOpen.Count')
wks = op.new_sheet()
col = 0
for i in range(n):
    lt_str = f'Fdlog.Get(A, {i+1});'
    op.lt_exec(lt_str)
    file = op.get_lt_str('%A')
    df = pd.read_table(file)    
    wks.from_df(df, col)
    wks.cols = wks.cols + 2
    wks.set_label(wks.cols - 2, "Current Density")
    wks.set_label(wks.cols - 2, "mA/cm^2", 'U')
    wks.set_label(wks.cols - 1, "Log Current Density")
    wks.set_label(wks.cols - 1, "mA/cm^2", 'U')
    col = wks.cols

Edited by - YimingChen on 02/02/2022 3:26:14 PM
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000