| Author |
Topic  |
|
|
mtremblay
Albania
Posts |
Posted - 02/24/2008 : 07:21:33 AM
|
Origin 8 XP
I have an OriginC script that was written with Origin7.5 that batch imports text files into Origin. The script imports one text file at a time into Origin, then saves an Origin project with the same file name as the text file, except the .txt extension is replaced with the .opj extension. This leaves me with an Origin project file for each text file. I have another script that applies the required graphs,again in batch mode, based on the name of each Origin Project.
I am having problems getting my scripts to run in Origin8.
The OriginC piece of code that I have been using to do the actual import of the text file is:
AscImpReadFileStruct(FilePath[ifile], &ascimp); wks.ImpotASCII(FilePath[ifile], ascimp);
In Origin 7.5 it puts the column name at the top correctly and it correctly added my label. My label has two lines, the first line is the units and the second line is an expanded description of the parameter. In Origin 8 it puts my column name under your new UNIT row. The unit line that was in my label is gone. And the expanded parameter description is in your new row called Comments. What do I need to change to put the column name in your new row called Short name and my label under your new row called Comments.
Another issue I noticed is the label that printed out as two rows in Origin7.5 prints out as one row in Origin8 using the command below. %a=Data1!wks.col$(3).label$; There is some special character printing now where the new row was starting.
The labtalk command =%[%a, @2] I used to strip out the units and parameter description now does not work correctly since it prints out as one line. What labtalk command can I use now to strip out my units and description.
|
|
|
cpyang
USA
1406 Posts |
Posted - 02/25/2008 : 11:16:38 PM
|
The following code should work in Origin 8. We have expended more detailed control on header control so I am afraid your OC code will need to be updated:
void dd() { ASCIMP ai; string strFile = GetOpenBox("*.txt"); if(strFile.IsEmpty()) return;// user cancel if(AscImpReadFileStruct(strFile, &ai)==0) { ai.iRenameCols =1; // use 1st line of header block to rename col ai.iLabels = 3; // header block has 3 lines ai.iMaxLabels = 1; // comments has only one line ai.nUnits=2; // use 2nd line of header block to set Units ASCIMPRESULT air; Worksheet wks; wks.Create(); int nRet = wks.ImportASCII(strFile, ai, &air); out_int("nRet = ", nRet); } else out_str("failed to read ascii file"); }
|
 |
|
|
mtremblay
Albania
Posts |
Posted - 02/26/2008 : 9:28:47 PM
|
Thanks. Worked as written.
Some txt files I handle have 4 header lines (first header line is the parameter name, second line is the parameter units, third line is the expanded description of the parameter, and the fourth line identifies the parameter as an analog or discrete parameter)
I tried some variations of the code you sent to handle a text file with 4 header lines, but with no luck. I believe the comment row will have to contain the expanded parameter discription and the parameter type indication.
What do I need to modify or add? |
 |
|
|
cpyang
USA
1406 Posts |
Posted - 02/27/2008 : 09:44:47 AM
|
Best would be to put these extra headers into user-defined-parameter rows. We will post an example shortly.
CP
|
 |
|
|
minimax
365 Posts |
Posted - 02/28/2008 : 05:57:34 AM
|
// This example to show how to set each sub headers to specified column label including uer defined parameter labels void Datasheet_ImportASCII_Ex3() { ASCIMP ai; string strFile = GetOpenBox("*.dat"); // or "*.txt" if(strFile.IsEmpty()) return;// user cancel if(AscImpReadFileStruct(strFile, &ai)==0) { ai.iAutoSubHeaderLines = 0; //set auto detected to false since will set sub header to col label by below codes ai.iSubHeaderLines = 4; // 1. LongName 2. Units 3. Expanded Discription(User defined) 4. Type Indication(User defined) // Notice when iAutoSubHeaderLines is 0, the index of ai.nLongName, ai.nUnits and ai.nFirstUserParams are begin from Main Header ai.nLongNames = ai.iHeaderLines; ai.nUnits = ai.iHeaderLines + 1; ai.nFirstUserParams = ai.iHeaderLines + 2; ai.nNumUserParams = 2; ai.iMaxLabels = 0; // Not set any header line to Comments label Worksheet wks; wks.Create(); if(0 == wks.ImportASCII(strFile, ai)) { // Set user parameter labels to specified names Grid grid; grid.Attach(wks); vector<string> vsUserLabels = {"Expanded Discription", "Type Indication"}; grid.SetUserDefinedLabelNames(vsUserLabels); wks.AutoSize(); // to resize worksheet. This method is very useful when data/text is longer than the width of cell } } else out_str("failed to read ascii file"); }
Max OriginLab Technical Support |
 |
|
|
mtremblay
Albania
Posts |
Posted - 02/28/2008 : 9:59:23 PM
|
Thank you for your quick response.
The code works but there is an issue with the display of some of the header information in the worksheet. In the Units row some of the columns have the parameter unit clearly visable while others do not. On a column that appears to have no unit assigned, if I double click on its cell, the cell turns white with the unit visable in the center of the cell. If I click on another cell the unit is again not visable in the cell. The characteristic also occurs with the user defined row called Type Indication. The long Name and Expanded description rows do not have this issue, the text in these rows are visable in each column. Any thoughts what may be causing this issue. |
 |
|
|
Iris_Bai
China
Posts |
Posted - 02/29/2008 : 02:32:09 AM
|
Hi, this is because the default setting of column labels is auto merged. To unable auto merged, can use ApplyFormat as the following codes to set. Or a simpler way, save Not auto merge in a worksheet template, and create your worksheet with this template. To set merge options in dialog: right click the gray area in worksheet and choose Properties..., in dialog choose Format Tab, select Units for Apply To and then choose None for Dynamic Merge and click Apply button. After do this, save this page as a template and give a good name.
#include <..\Originlab\okThemeID.h> TreeNode find_style_nodes_by_name(TreeNode trRoot, LPCSTR lpcszName) { TreeNode trProp; TreeNode trNameStyles; bool bRet = octree_theme_tree_get_node_by_id(&trNameStyles, &trRoot, OTID_NAMESTYLES, 3, true); if(trNameStyles) { foreach(TreeNode trNode in trNameStyles.Children) { TreeNode trName; bRet = octree_theme_tree_get_node_by_id(&trName, &trNode, OTID_NAMESTYLE_NAME, 3, true); if(trName && 0 == trName.strVal.CompareNoCase(lpcszName)) { trProp = trName.Parent(); break; } } } return trProp; }
void test_wks_merge(string strStyleName = "ogUnit", int nMergeFormat = GMC_NONE) { Worksheet wks = Project.ActiveLayer(); if(!wks) return; Tree tr; tr = wks.GetFormat(FPB_ALL, FOB_ALL, true, true); TreeNode trUnitFormat = find_style_nodes_by_name(tr, strStyleName); //ogLongName, ogComment, ogUDL(User Defined Labels), ogData(for Data Area) if(trUnitFormat) { trUnitFormat.Style.Merge.nVal = nMergeFormat; if(0 == wks.UpdateThemeIDs(tr.Root, "Error", "Unknown tag")) //no error { if(wks.ApplyFormat(tr, TRUE, TRUE, TRUE)) wks.GetPage().Refresh(); } } }
Iris |
 |
|
|
mtremblay
Albania
Posts |
Posted - 03/01/2008 : 3:30:13 PM
|
| I used the worksheet template method. Thanks. |
 |
|
| |
Topic  |
|
|
|