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
 dynamic name
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

akerstan

Germany
2 Posts

Posted - 06/05/2009 :  07:30:49 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hallo,

I want to plot data from different worksheets, that is why I wrote a loop over all worksheets. This is working quite good.
Now in each loop a curve is created.

I would like to generate each curve with a different name. Therefor I did this:
(is there no other way to convert an integer to a string, than doing this by vectors???)

vector <int> vecn;

vector <string> veccount;


foreach (Folder sf in fldRoot.Subfolders) //loop over the subfolders of root folder
{

foreach (PageBase pg in sf.Pages) //loop over the pages in the subfolder
{
if (pg.GetType() == EXIST_WKS) //check if the page is an worksheet page
{

WorksheetPage wp(pg);
Worksheet wks(wp.Layers(0));
//


vecn=vecn+1;
//
convert_int_vector_to_string_vector( vecn, veccount);

// there must be an easier way to do this I know


string curvename= "crv"+veccount[0];

Curve "curvename";


I hope this is possible in some way.

bye,

Ann

Sophy

China
Posts

Posted - 06/08/2009 :  02:56:13 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi, akerstan:

I'd like to point out some coding problem in you code before solving your problem.

You might have misused the vector<int> vecn, the problem is that vecn = vecn + 1, means that every item in vector vecn will increase by 1, e.g. {1, 2, 3} will become {2, 3, 4}.

If you want to convert a integer to a string, just assign the integer to a string variable, then Origin C can convert it automatically. I hope the following code will help you on understanding how it works.


#include <Origin.h>
#define	STR_CRV_NAME_PREFIX	"crv"
void dynamic_name_ex()
{
	vector<string>	vsCurveNames(0); //declare a string vector to store all curve names and reset it.
	int				nNumCrv = 0; //number of curves
	
	//get root folder
	Folder rootFdr = Project.RootFolder;
	
	foreach(Folder SubFdr in rootFdr.Subfolders)
	{
		foreach(PageBase pb in SubFdr.Pages)
		{
			if ( pb.GetType() == EXIST_WKS )
			{
				WorksheetPage wksPage(pb);
				foreach(Layer wkslyr in wksPage.Layers)
				{
					Worksheet wks(wkslyr);
					//do something
					//...
					
					//add new curve name
					nNumCrv++;
					string strCrvName = STR_CRV_NAME_PREFIX + nNumCrv; //Origin C will convert nNumCrv to string automatically, say 2 to "2", and catenate two strings and assign to strCrvName
					vsCurveNames.Add(strCrvName); //add to string vector;
				}
			}
		}
	}
}


BTW, you might have interest in how to plot all xyranges in current project on one graph, please refer to http://ocwiki.originlab.com/index.php?title=OriginC:Plot_all_worksheets_in_one_graph_layer
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