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 for Programming
 Forum for Origin C
 How to select columns in Origin C?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

cjbf

UK
8 Posts

Posted - 09/13/2004 :  8:32:24 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): OriginPro 7.5 SR4
Operating System: Windows XP SP2

I am trying to select various columns using Origin C. I can't find a way to do it. Selection.Add(orgobj) can only add one column (repeating the process fails). Also, it does not affect the actual selection visible in the worksheet, so it can't be the right sort of selection. To read what is selected, wks.GetSelectedColumns(vector<int> v) works fine, and matches the visible selected columns. So, is there (or can there be) a corresponding command to select the columns, please?

Our general need is to process (plot or whatever) a number of "sweeps" of data (eg XYYYXYYY...) at the same time. I can easily set them to be XYYY etc, but selecting X and the first Y of each "sweep", so that users can use standard dialog boxes to pick options, looks hard without a program. That's why I need to be able to select columns in Origin C (or LabTalk). I can't be alone in needing this - are there better ways or programs to help?

Any help appreciated!
Thanks,
CF

Mike Buess

USA
3037 Posts

Posted - 09/13/2004 :  10:11:16 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi CF,

This works in LabTalk for a wks named Data1...

Data1!wks.colsel(i,n); // n=1 (select column i) or n=0 (deselect column i)

Use it in Origin C like this...

string wksName = "Data1";
int colnum = 2;
LT_execute(wksName + "!wks.colsel(" + colnum + ",1);");

-or-

Worksheet wks("Data1");
int colnum = 2;
wks.LT_execute("wks.colsel(" + colnum + ",1);");

Don't forget that LabTalk column indices are 1-based (1,2,3,...) whereas Origin C indices are 0-based (0,1,2,...).

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 09/13/2004 10:19:14 PM
Go to Top of Page

cjbf

UK
8 Posts

Posted - 09/14/2004 :  6:06:17 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Mike,
Many thanks for the swift and helpful reply. It works well!
In case anyone will find them useful, here are my routines to select x and y columns in a set of "sweeps", and to set the x (and y) columns in each sweep:

void my_selcols(string WinName, int ncolPerSweep, int xcol, int ycol)
// worksheet WinName or active one if WinName is ""
// Each "sweep" is a set of ncolPerSweep columns;
// selects columns xcol and ycol (>=0) of each sweep
{ int i,k,totalncol;
Worksheet wks(WinName);
if (WinName=="")
wks=Project.ActiveLayer();
if(wks)
{totalncol=wks.GetNumCols();
for (i=0;i<totalncol;i+=ncolPerSweep)
{for (int k=0;k<ncolPerSweep;k++)
wks.LT_execute("wks.colsel(" + (k+i+1) + ","+(k==xcol || k==ycol)+");");
}
}
}


void my_setxcols(string WinName, int ncolPerSweep, int xcol)
// worksheet WinName or active one if WinName is ""
// Each "sweep" is a set of ncolPerSweep columns;
// sets column xcol (>=0) of each sweep to be an X column, the rest to be Y columns
{ int i,k,totalncol,type;
Worksheet wks(WinName);
if (WinName=="")
wks=Project.ActiveLayer();
if(wks)
{totalncol=wks.GetNumCols();
out_int("Num of columns =", totalncol);
for (i=0;i<totalncol;i+=ncolPerSweep)
{for (int k=0;k<ncolPerSweep;k++)
{Column cc=wks.Columns(i+k);
if (k==xcol) type=1; else type=2;
printf("col %i type=%i\n",i+k,type);
switch(type)
{case 1: cc.SetType(OKDATAOBJ_DESIGNATION_X); break;
case 2: cc.SetType(OKDATAOBJ_DESIGNATION_Y); break;
default: printf("Unknown type: %i\n",type);
}
}
}
}
else
printf("Unable to find worksheet %s - is it on top?\n",WinName);
}

Yours,
Chris.
Go to Top of Page

Iris_Bai

China
Posts

Posted - 09/24/2004 :  02:12:14 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Chris.

There is another method to get selected columns in worksheet by Origin C. The following is an example:

 
void get_selected_cols()
{
vector<int> v;
Worksheet wks = Project.ActiveLayer();
BOOL bOK = wks.GetSelectedColumns(v);
string strCols = "Column ";
for(int ii=0; ii<v.GetSize(); ii++)
{
strCols = strCols + v[ii] + " ";
}
strCols += "is selected";
out_str(strCols);
}



void get_selected_range()
{
Worksheet wks = Project.ActiveLayer();
int r1, c1,r2, c2;
string strAddress;
int seltype = wks.GetSelectedRange(r1, c1, r2, c2, &strAddress);

printf("sel = %d\tr1 = %d\tc1 = %d\tr2 = %d\tc2 = %d\n", seltype, r1, c1, r2, c2);
out_str(strAddress);
}


Iris
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