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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Difficulty with multiple ascii import script

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
SethM Posted - 01/31/2022 : 1:50:32 PM
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.
1   L A T E S T    R E P L I E S    (Newest First)
YimingChen Posted - 02/02/2022 : 3:24:28 PM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000