Author |
Topic  |
|
couturier
France
291 Posts |
Posted - 11/05/2018 : 2:08:40 PM
|
Origin Ver. and Service Release (Select Help-->About Origin): 2019 Operating System:win 10
Hi,
I'm stuck with a rather basic operation 
I have a range in a string, in the form of Book1_A@3, for example. From here, how can I construct a column object, or at least get the index of that col (I already have the corresponding wks object) ?
I've searched in help and forum but all examples assumes we know the col index. I've tried DatasetObject Xcol( strX ); // where strX= Book1_A@3 int idxcol = Xcol.GetIndex(); but this returns -1
Thanks |
|
couturier
France
291 Posts |
Posted - 11/05/2018 : 2:23:47 PM
|
I can also get the range string as [Book1]Sheet1!B, but I'm equally stuck here.
 |
 |
|
nick_n
Finland
125 Posts |
Posted - 11/05/2018 : 4:22:14 PM
|
Hi, Did you try: parse_data_range_str? Best regards,
Nikolay |
 |
|
nick_n
Finland
125 Posts |
Posted - 11/05/2018 : 4:27:20 PM
|
oops, you need index :(
Nikolay |
 |
|
nick_n
Finland
125 Posts |
Posted - 11/05/2018 : 4:34:33 PM
|
Hi, In my case I used "XFBase xf ("get_wks_sel");" and then just parse index of selected column. Not sure if it suitable for you. Best,
Nikolay |
 |
|
Castiel
343 Posts |
Posted - 11/05/2018 : 9:28:35 PM
|
quote: Originally posted by couturier
Origin Ver. and Service Release (Select Help-->About Origin): 2019 Operating System:win 10
Hi,
I'm stuck with a rather basic operation 
I have a range in a string, in the form of Book1_A@3, for example. From here, how can I construct a column object, or at least get the index of that col (I already have the corresponding wks object) ?
I've searched in help and forum but all examples assumes we know the col index. I've tried DatasetObject Xcol( strX ); // where strX= Book1_A@3 int idxcol = Xcol.GetIndex(); but this returns -1
Thanks
The last time I saw a dataset named similar to Book1_A@3 must be more than 5 years ago. In what case do you prefer the dataset name to a column object / have to use the dataset name rather than a column object?
Code in 2 lines:DataObject &ref = Project.GetDataObject("Book1_A@3");
int n = ref.GetIndex();
Generally, you may check if the dataset is one of the columns in a worksheet: DWORD Project::GetDatasetInfo(LPCTSTR lpcszDatasetName, BOOL bNeedFolderInfo = FALSE, LPDatasetInfoMore pstMore = NULL)
&&&&&&&&&
&&&
&&
& _____ ___________
II__|[] | | I I |
| |_|_ I I _|
< OO----OOO OO---OO
**********************************************************
|
 |
|
Castiel
343 Posts |
Posted - 11/05/2018 : 9:39:42 PM
|
quote: Originally posted by couturier
I can also get the range string as [Book1]Sheet1!B, but I'm equally stuck here.

A range string may refer to objects not just columns. To get the corresponding columns:
1) Get the corresponding DataRange, // #include <xfutils.h>
DataRange dr;
BOOL bInit = okxf_init_range_from_string(&dr, "[Book1]Sheet1!B");
2) Get the dataset namesvector<string> vstrDatasetNames;
dr.GetNamesOfDatasets(vstrDatasetNames);
3) Get the column index as my previous post of this topic said.
&&&&&&&&&
&&&
&&
& _____ ___________
II__|[] | | I I |
| |_|_ I I _|
< OO----OOO OO---OO
**********************************************************
|
 |
|
yuki_wu
896 Posts |
|
couturier
France
291 Posts |
Posted - 11/09/2018 : 12:09:18 PM
|
Sorry for replying so late.
@Nikolay: Thanks for helping but I don't have any selection so get_wks_sel won't work;
@ Yuki: Thanks for helping but I'd rather code that in OC
@Castiel: Thank you very much once again. I could do what I wanted with your examples :-)
Though I've written thousands of OC lines code so far, I'm still highy frustrated of struggling with basic operations that are still unclear to me, such as: - from a dp object, how to simply get corresponding column objects ? - from a wks and column name (shortname or longname), how to get corresponding column object ? |
 |
|
Castiel
343 Posts |
Posted - 11/11/2018 : 10:54:03 PM
|
quote: Originally posted by couturier
Sorry for replying so late.
@Nikolay: Thanks for helping but I don't have any selection so get_wks_sel won't work;
@ Yuki: Thanks for helping but I'd rather code that in OC
@Castiel: Thank you very much once again. I could do what I wanted with your examples :-)
Though I've written thousands of OC lines code so far, I'm still highy frustrated of struggling with basic operations that are still unclear to me, such as: - from a dp object, how to simply get corresponding column objects ? - from a wks and column name (shortname or longname), how to get corresponding column object ?
You may post any basic operations unclear to you. In one post maybe. I shall try to take part in the topic whenever possible.
For the 2 issues about getting Column Object:
1) Get The Corresponding Column objects from a DataPlot object
A DataPlot may be created with columns, matrix objects, and even loose datasets.
In most cases, you can 1.1.1) get the DataRange of the DataPlot DataRange dr; dp.GetDataRange(dr); 1.1.2) get the dataset names from the datarange vector<string> vstrDatasetNames; dr.GetNamesOfDatasets(vstrDatasetNames); 1.1.3) get the corresponding DataObject, which may be a Column or a MatrixObject DataObject &ref = Project.GetDataObject(vstr[ i ]);
However, this won't work for DataPlot objects created from loose datasets. Problem in DataRange::GetNamesOfDatasets(). Bug maybe in Origin 2019.
Another way to get the corresponding DataObject/Dataset then is preferred:
1.2.1) get details of DataPlot as DataPlotStrings dps; int nPlotType = dp.GetPlotType(&dps); // The method name is to some extend misleading... 1.2.2) dps contains information about book/sheet/column and more. To filter out the extra details: string strBook, strSheet, strPlot, strLongName, strCol, strVal; int nRow; bool bRealLongName = false; bool bRet = get_plot_info(COLDESIG_Y, dps, strBook, strSheet, strPlot, strLongName, strCol, nRow, strVal, bRealLongName);
The COLDESIG_Y can be replaced with an integer from COLDESIG_X (inclusive) to COLSESIG_TOTAL_NUM (exclusive) accordingly.
Be aware that if the X data is from sampling interval of Y, you can get the from and step using this function: BOOL GetDatasetXFromStep(LPCSTR lpcszDatasetName, double* lpdbFrom, double* lpdbStep); or get the Y column and get details from it as Column::IsEvenSampling( double * px0 = NULL, double * pxInc = NULL, string * pStrXUnits = NULL, string * pStrXLongName = NULL )
1.2.3) Once you have the book/sheet/column etc., it turns into an issue of the second one
2) Get the corresponding Column object from a Worksheet and Column name (short name or long name)
Both Worksheet and MatrixSheet are derived from Datasheet, in which there is a method:DataObject Datasheet::FindCol( LPCSTR lpcszColLabel, int nColBegin = 0, BOOL bCaseSensitive = false, BOOL bFullMatch = true, int nColEnd = -1, BOOL bAllowShortName = true ) the returned DataObject can be a Column or MatrixObject.
There are details I do not described above, supposing it's been sufficient to solve you problem in most cases, keeping it as less complicated as possible.
&&&&&&&&&
&&&
&&
& _____ ___________
II__|[] | | I I |
| |_|_ I I _|
< OO----OOO OO---OO
**********************************************************
|
 |
|
couturier
France
291 Posts |
Posted - 11/12/2018 : 03:37:01 AM
|
Thanks a lot 
It is both reassuring that I hadn't missed a simple function and surprising that things have to be so complicated  |
Edited by - couturier on 11/12/2018 03:37:20 AM |
 |
|
Castiel
343 Posts |
Posted - 11/12/2018 : 04:08:48 AM
|
quote: Originally posted by couturier
Thanks a lot 
It is both reassuring that I hadn't missed a simple function and surprising that things have to be so complicated 
It doesn't necessarily have to be complicated if you are sure about the graph is created with column(s).
It's complicated in that the input data can be other than columns. For example, loose dataset (in project level or in session level), sampling interval, matrix, etc. This is something you may attention to if the code is targeting at general graphs. Otherwise methods you need have all been documented.
&&&&&&&&&
&&&
&&
& _____ ___________
II__|[] | | I I |
| |_|_ I I _|
< OO----OOO OO---OO
**********************************************************
|
 |
|
|
Topic  |
|
|
|