T O P I C R E V I E W |
vegetable bird |
Posted - 01/15/2018 : 07:36:18 AM OriginPro 2015(64) Operating System: win10 I have problem in importing .txt files using Origin C. In command window, following commands importing some .txt files works: string path$="D:\"; cd path$; findFiles ext:="txt"; impASC; In code builder I want to do the same thing, however, the methods Origin C Reference\Internal Origin Objects\Datasheet\ImportASCII supply do not work even if there is only one .txt file to be imported(GetOpenBox(*.txt)). I typed the function name "Datasheet_ImportASCII_Ex1" in Command & Results, nothing happened. There must be something wrong, who can help me?
|
13 L A T E S T R E P L I E S (Newest First) |
yuki_wu |
Posted - 02/01/2018 : 05:12:25 AM Hi,
Please read: https://www.originlab.com/doc/Origin-Help/Wkbk-Saved-with-Template#Origin_Import_Filter_.28.2A.OIF.29_file
Also, use the search feature of the website I introduced on Jan 16.
Regards, Yuki OriginLab |
vegetable bird |
Posted - 01/31/2018 : 9:07:58 PM Hi, How to generate *.oif file?
|
yuki_wu |
Posted - 01/29/2018 : 10:27:05 PM Hi,
Please READ the documnent of load_import_filter carefully: https://www.originlab.com/doc/OriginC/ref/load_import_filter
Note that oif file is the filter file, nLocation is used to specify the folder where the filter file is, not where the data file is. If you only want to simply import a txt file, please refer to the example below:
#include <Origin.h>
int Datasheet_ImportASCII_Ex1()
{
int iStatus;
ASCIMP ai;
string strFile = GetOpenBox("*.txt");
if(AscImpReadFileStruct(strFile,&ai) == 0)
{
ai.iRenameWks = 1; //to rename worksheet from filename
ai.iRenameCols = 1; //0 to keep default column names, 1 to rename columns using 1st line of header block
Worksheet wks;
wks.Create();
return wks.ImportASCII(strFile, ai);
}
else
return -99;
}
If you hope to execute the LabTalk script in Code Builder: 1. Create a new LabTalk Script File by selecting File: New 2. Copy and paste the script into the file:
[importfile]
string path$ = system.path.program$ + "Samples\Import and Export\";
findfiles ext:=matrix_data_with_xy.txt;
impASC; 3. Save LabTalk Script File 4. Execute the importfile section in Command&Result window
Run.section(OGSFileName, importfile) More info about how to run script form OGS file: https://www.originlab.com/doc/LabTalk/Tutorials/Tutorial-Get-Started#Run_Script_From_OGS_File
Regards, Yuki OriginLab
|
vegetable bird |
Posted - 01/28/2018 : 8:55:03 PM Where is the ** Data.oif? And in my example, how to set nLocation number? |
yuki_wu |
Posted - 01/26/2018 : 01:19:04 AM Hi,
Please read the documnent of load_import_filter carefully again. nLocation is used to specified the locaton where you put the filter file. If
string strFilterName = "Data"; & int nLocation = 0;
It means that you should put the import filter file (Data.oif) into the folder that includes the data file you are going to import.
FYI, you may need debugging in Code Builder when you are coding. Please take a look at this page, it should help: https://www.originlab.com/doc/CodeBuild/Compiling-And-Debugging-Origin-C-Files
Regards, Yuki OriginLab
|
vegetable bird |
Posted - 01/24/2018 : 9:30:45 PM #include <..\Originlab\FileImport.h> void import_files_with_specify_filter_ex() { Page pg = Project.Pages(); // Active Page // Get page book name string strPageName = pg.GetName(); // Get page active layer index int nIndexLayer = pg.Layers().GetIndex(); // Get Origin sample folder //string strPath = GetAppPath(TRUE) + "Samples\\Import and Export\\"; string strPath = "D:\\"; // List all file names need to imported StringArray saFileNames; saFileNames.Add(strPath + "Data\\data1.txt"); saFileNames.Add(strPath + "Data\\data2.txt"); //saFileNames.Add(strPath + "pCLAMP\\93310C08.DAT"); //saFileNames.Add(strPath + "pCLAMP\\93310C10.DAT"); //saFileNames.Add(strPath + "pCLAMP\\93311C01.DAT"); // specify .oif filter name, location see the setting of nLocation below. string strFilterName = "Data"; // import filter tree // about filter settings, refer to imppClamp xfunction tree variable "options" Tree trFilter; int nLocation = 0; // nLocation //0 - Data file folder //1 - Origin working filter folder //2 - User filter folder //3 - In target Page //4 - Full path int nRet; nRet = load_import_filter(strFilterName, saFileNames[0], strPageName, nLocation, trFilter); if ( 0 == nRet ) out_str("Success to load import filter!"); else out_str("Failed to load import filter!\nPlease check strFilterName and nLocation if assigned correctly"); if ( 0 == nRet ) { nRet = import_files(saFileNames, strPageName, nIndexLayer, trFilter); if ( 0 == nRet ) out_str("Success to import!"); else out_str("Failed to import!"); } }
Command & Results prints: X> import_files_with_specify_filter_ex Failed to load import filter! Please check strFilterName and nLocation if assigned correctly I have tried all the nLocation number, but the result is the same, so what's wrong?
|
yuki_wu |
Posted - 01/18/2018 : 10:08:51 PM Hi,
1. If you want to access other folders, just defined it directly like:
string strPath = "C:\\Program Files"; 2. You commented this line:
nRet = import_files(saFileNames, strPageName, nIndexLayer, trFilter); which is exactly going to import the file, so the code doesn’t work.
3. I think you actually hope to use LabTalk but not Origin C, please go through this Guide to see if LabTalk is what you are looking for: https://www.originlab.com/doc/LabTalk/guide
Regards, Yuki OriginLab
|
vegetable bird |
Posted - 01/18/2018 : 9:47:55 PM #include <..\Originlab\FileImport.h> void import_files_with_specify_filter_ex() { Page pg = Project.Pages(); // Active Page // Get page book name string strPageName = pg.GetName(); // Get page active layer index int nIndexLayer = pg.Layers().GetIndex(); // Get Origin sample folder string strPath = GetAppPath(TRUE) + "Samples\\Import and Export\\"; // List all file names need to imported StringArray saFileNames; saFileNames.Add(strPath + "pCLAMP\\93310C08.DAT"); saFileNames.Add(strPath + "pCLAMP\\93310C10.DAT"); saFileNames.Add(strPath + "pCLAMP\\93311C01.DAT"); // specify .oif filter name, location see the setting of nLocation below. string strFilterName = "pCLAMP"; // import filter tree // about filter settings, refer to imppClamp xfunction tree variable "options" Tree trFilter; int nLocation = 1; // Origin exe folder, more options see the document of load_import_filter function. int nRet; nRet = load_import_filter(strFilterName, saFileNames[0], strPageName, nLocation, trFilter); //if ( 0 == nRet ) //out_str("Success to load import filter!"); //else //out_str("Failed to load import filter!\nPlease check strFilterName and nLocation if assigned correctly"); // //if ( 0 == nRet ) //{ //nRet = import_files(saFileNames, strPageName, nIndexLayer, trFilter); // //if ( 0 == nRet ) //out_str("Success to import!"); //else //out_str("Failed to import!"); //} }
The example above is of little value, one reason is for the function GetAppPath() limits the path to the Program path or the User Files path, but I want to define my own path. The other is that if I comment the bottom part of the code which I think should be commented, the import does't work. What I want is some code like the Command Window style, it's simple and efficient. Can the commands in command window which I send first time be translated to Code Builder mode?
|
yuki_wu |
Posted - 01/16/2018 : 10:03:41 PM Hi,
I suppose you are playing about the example on this page, right? https://www.originlab.com/doc/OriginC/ref/load_import_filter
Please pay attention to the Output Window to see if linking is done. If linking failed, run run.LoadOC(Originlab\FileImport.c, 16); once again.
Regards, Yuki OriginLab
|
vegetable bird |
Posted - 01/16/2018 : 8:05:20 PM After I run run.LoadOC(Originlab\FileImport.c, 16); in Command Window the linking procedure still can't be passed. Output gives following information: C:\Program Files\OriginLab\Origin2015\OriginC\Originlab\FileImport.c(1035) :Error, Function ConvFilter@CAAAAAAAOGAAAAAAOGAAAAAA was called, but its body could not be located during linking. Linking Failed! What should I do to call load_import_filter_ex? |
yuki_wu |
Posted - 01/16/2018 : 03:50:08 AM Hi,
Try this function: https://www.originlab.com/doc/OriginC/ref/import_files
A small tip: You can enter some keywords into the search box and click the Search button to find the related topic.

Regards, Yuki OriginLab
|
vegetable bird |
Posted - 01/15/2018 : 9:23:13 PM I find another tip for importing files in the Origin C Programming Guide\Importing\Importing Data subfolder, following code works: void imp() { string strFile = "D:\\result.txt"; // some data file name ASCIMP ai; if(0 == AscImpReadFileStruct(strFile, &ai) ) { LTVarTempChange progressBar("@NPO", 0); // 0 = disable progress bar // Get active worksheet from active work book. Worksheet wks = Project.ActiveLayer(); if(0 == wks.ImportASCII(strFile, ai)) out_str("Import data successful."); } } Now I come up with a new question that is how to import more than one file at one time? |
yuki_wu |
Posted - 01/15/2018 : 8:49:00 PM Hi,
This example works fine on my machine. Have you compiled and linked the source file in Code Builder before you executed it? If not, could you please have a look at this page? https://www.originlab.com/doc/OriginC/guide/Basic-Features
Regards, Yuki OriginLab
|
|
|