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
 Origin Forum
 labtalk syntax to copy filename
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

EigenGoofy

64 Posts

Posted - 05/12/2011 :  4:30:33 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
By importing Multiple ASCII or importing Wizard, the data from two files "r1T.XVG" and r2E.XVG" have been added on the two columns A and B on a worksheet. Then I need write comments on the column A by typing "r1T", and on the column B by typing "r2E".

Question:
How can I use labtalk syntax or script to copy the filename "r1T.XVG" without ".XVG" to the comment table on the column A without directy typing?

EigenGoofy

64 Posts

Posted - 05/12/2011 :  10:28:49 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Let's explan more specific.

When using "Import Wizard", click "next" multiple times until reaching to the last page where it asks to save the Filter, then tick the box which indicates "Specify advanced filter options" and click "next" again. It follows that a window asks to write labtalk code which will be executed after a successful import.

Here, I expect to write segment of labtalk code which will copy the filenames without extension suffix to the comment table on the column A and column B respectively. And this code shall be a little more applicable than just one case. For example, if the two files are not "r1t.XVG" and "r2E.XVG", but "wTj.XVG" and "wFe.XVG", then the exactly same code will copy "wTj" to the comment on the column A, and "wFe" to the comment on the column B, rather than still to copy "r1t" to column A and "r2E" to column B; in other words, without specifying the corresponding filepath, the code is able to recognize the filename.

Actually, I find that the Main header (MH) of a file contains the information of filename. I have tried to copy the information from MH to comment (C) via the "Import Wizard", Origin does not allow to do in this way!

Anybody can help? Thank you very much!
Go to Top of Page

greg

USA
1378 Posts

Posted - 05/13/2011 :  4:57:22 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The data you are trying to get is in a tree stored in the page.
You can see the info by showing the Organizer. (Right click on the Workbook Title bar.) And although OriginC has a direct method to get a filename without the extension, you can do it in LabTalk with a few extra steps.

Here is an example that reads the filename (minus the extension) and applies it to comments:

// Get the file + ext
string strFile$ = page.info.system.import.filename$;
// Get the ext
string strExt$ = strFile.GetFileExt()$;
// Get the file - ext
strFile$ = strFile.Left(strFile.Len() - strExt.Len() - 1)$;
wcol(wks.ncols)[C]$ = str$;

and here is a variation that writes to a custom header row:

string strFile$ = page.info.system.import.filename$;
string strExt$ = strFile.GetFileExt()$;
strFile$ = strFile.Left(strFile.Len() - strExt.Len() - 1)$;
wks.userparam1$ = FileName; // Define a user parameter row
wks.userparam1 = 1; // Show it
wcol(wks.ncols)[FileName]$ = strFile$;

BTW : The File Name Options page of the Import Wizard has a check box to Append file name to column comments. You need a script only because you do not want the extension.
Go to Top of Page

EigenGoofy

64 Posts

Posted - 05/13/2011 :  6:10:45 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by greg


// Get the file + ext
string strFile$ = page.info.system.import.filename$;
// Get the ext
string strExt$ = strFile.GetFileExt()$;
// Get the file - ext
strFile$ = strFile.Left(strFile.Len() - strExt.Len() - 1)$;
wcol(wks.ncols)[C]$ = str$;




Thank you, greg!
However, if using the code on the first line:

string strFile$ = page.info.system.import.filename$;

This will only assign one of the filename to strFile$, say, strFile$ = r2E.XVG. And r1T.XVG must be totally missing. After you mentioned, I have just checked the Organizer, and confirmed that although I imported from two different files, but the resulting filename shall only be one of the two filenames. On the Organizer, if look at Imported Files, there are TWO different Filenames which are wanted to apply to comments on the column A and column B. So I have tried, like:

string strFile$ = Imported Files.name$;

However, it can not work.

One of the staff here told me to use the following code to get rid of extension:

bbb$ = strFile.GetToken(1,".")$;

Which works!

Thank you again, greg. I am looking forward to see how you get the two different imported filenames, such as r1T and r2E, by using perhaps two different strings.
Go to Top of Page

easwar

USA
1964 Posts

Posted - 05/13/2011 :  7:15:02 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Here is another possible solution:
1> Use import wizard to import your multiple files

2> On first page of wizard set Import Mode drop-down to "Start New Columns" so all files come into same sheet as new columns

3> On the 2nd page (File name Options), under Append, check the "file name to column comments" check box, and uncheck the "Include path when appending file name"

4>Then in the Advanced Options page, put this script:
for(int ii=1; ii<=wks.ncols; ii++)
{
string str$=wcol(ii)[C]$;
wcol(ii)[C]$ = str.GetToken(1,'.')$;
}


Then the script will remove the file extension part from the comments from all columns.

Easwar
OriginLab
Go to Top of Page

EigenGoofy

64 Posts

Posted - 05/13/2011 :  9:31:20 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by easwar

Hi,

Here is another possible solution:
1> Use import wizard to import your multiple files

2> On first page of wizard set Import Mode drop-down to "Start New Columns" so all files come into same sheet as new columns

3> On the 2nd page (File name Options), under Append, check the "file name to column comments" check box, and uncheck the "Include path when appending file name"

4>Then in the Advanced Options page, put this script:
for(int ii=1; ii<=wks.ncols; ii++)
{
string str$=wcol(ii)[C]$;
wcol(ii)[C]$ = str.GetToken(1,'.')$;
}


Then the script will remove the file extension part from the comments from all columns.

Easwar
OriginLab




Oh, my god. I always had a super-long name on the tables of comments until now I just know from Easwar that there is a GOLDEN box hiden there so that I can uncheck the "Include path when appending file name"!

Thank you, Easwar and your "for" sentence...

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