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
 merging plots from different worksheets
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

olsy

29 Posts

Posted - 11/10/2011 :  11:39:06 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 8.5Pro
Operating System:win7

Hi!
i got a new trouble with coding:
I have several worksheets. They all have the same structure (columns names). I´m looking for the worksheet with specified names and build plots for columns 5-10 of this worksheets.
For example now i have two wks for which i plot graphs. And after my program i have 12 graphs. But what i want to have it is only 6 graph pages with two data plots. Like on the pic for all 6 columns:

now i use this code:
WorksheetPage wpSource=Project.Pages(-1);
		if(wpSource.IsValid()==true)
		{
			WorksheetPage WPtarget;
			string strName = "PlotWks";
			strName.TrimLeft();
			strName.TrimRight();
			strName.MakeLower();
			if(WPtarget.Create("xxx",CREATE_HIDDEN)==true)
			{
				Worksheet WksEmpty(WPtarget.Layers(0));
				WksEmpty.SetName("xxx"+strName);
				int NumLayers=0;
				foreach (Layer Layr in wpSource.Layers)
				{
					Worksheet WksSearch(Layr);
					if(WksSearch.IsValid()==true)
					{
						string strWksName=WksSearch.GetName();
						if(is_str_match_begin(strName,strWksName)==true)
						{
							
			Worksheet wksdata(Layr);				
			DataRange dr1;
		    DataRange dr2;
		    DataRange dr3;
		    DataRange dr4;
		    DataRange dr5;
		    DataRange dr6;
 
		    dr1.Add(wksdata, 1, "X");
		    dr1.Add(wksdata, 5, "Y");
		    dr2.Add(wksdata, 1, "X");
		    dr2.Add(wksdata, 6, "Y");
		    dr3.Add(wksdata, 1, "X");
		    dr3.Add(wksdata, 7, "Y");
		    dr4.Add(wksdata, 1, "X");
		    dr4.Add(wksdata, 8, "Y");
		    dr5.Add(wksdata, 1, "X");
		    dr5.Add(wksdata, 9, "Y");
		    dr6.Add(wksdata, 1, "X");
		    dr6.Add(wksdata, 10, "Y");
		 
		    GraphPage gp1;
		    gp1.Create("origin", CREATE_HIDDEN);
		    GraphLayer gl1 = gp1.Layers();
		 
		    //GAP_GROUP_PLOTS is specified by default, so if data range has multiple plots, they will be grouped
		    gl1.AddPlot(dr1, IDM_PLOT_LINESYMB);
		 
		    gl1.Rescale();
		    legend_update(gl1); // to update the legend loaded in from template
		    gp1.SetShow();
		    
		    GraphPage gp2;
		    gp2.Create("origin", CREATE_HIDDEN);
		    GraphLayer gl2 = gp2.Layers();
		 
		    //GAP_GROUP_PLOTS is specified by default, so if data range has multiple plots, they will be grouped
		    gl2.AddPlot(dr2, IDM_PLOT_LINESYMB);
		 
		    gl2.Rescale();
		    legend_update(gl2); // to update the legend loaded in from template
		    gp2.SetShow();
		
		    GraphPage gp3;
		    gp3.Create("origin", CREATE_HIDDEN);
		    GraphLayer gl3 = gp3.Layers();
		 
		    //GAP_GROUP_PLOTS is specified by default, so if data range has multiple plots, they will be grouped
		    gl3.AddPlot(dr3, IDM_PLOT_LINESYMB);
		 
		    gl3.Rescale();
		    legend_update(gl3); // to update the legend loaded in from template
		    gp3.SetShow();
		        	
		    GraphPage gp4;
		    gp4.Create("origin", CREATE_HIDDEN);
		    GraphLayer gl4 = gp4.Layers();
		 
		    //GAP_GROUP_PLOTS is specified by default, so if data range has multiple plots, they will be grouped
		    gl4.AddPlot(dr4, IDM_PLOT_LINESYMB);
		 
		    gl4.Rescale();
		    legend_update(gl4); // to update the legend loaded in from template
		    gp4.SetShow();
		    
		    GraphPage gp5;
		    gp5.Create("origin", CREATE_HIDDEN);
		    GraphLayer gl5 = gp5.Layers();
		 
		    //GAP_GROUP_PLOTS is specified by default, so if data range has multiple plots, they will be grouped
		    gl5.AddPlot(dr5, IDM_PLOT_LINESYMB);
		 
		    gl5.Rescale();
		    legend_update(gl5); // to update the legend loaded in from template
		    gp5.SetShow();
		    
		    GraphPage gp6;
		    gp6.Create("origin", CREATE_HIDDEN);
		    GraphLayer gl6 = gp6.Layers();
		 
		    //GAP_GROUP_PLOTS is specified by default, so if data range has multiple plots, they will be grouped
		    gl6.AddPlot(dr6, IDM_PLOT_LINESYMB);
		 
		    gl6.Rescale();
		    legend_update(gl6); // to update the legend loaded in from template
		    gp6.SetShow();
    
    		Tree tr;
	    	tr.Root.Curves.Curve1.Line.Color.nVal = 0; // red
	        tr.Root.Curves.Curve1.Line.Width.dVal = 3;
			tr.Root.Axes.X.Scale.MinorTicksCount.nVal = 3; // auto add nodes and assign 3 to MinorTicksCount  
	        if( 0 == gl1.UpdateThemeIDs(tr.Root) ) // if no err
	        {
	            gl1.ApplyFormat(tr, true, true);
	        }
    		if( 0 == gl2.UpdateThemeIDs(tr.Root) ) // if no err
	        {
	            gl2.ApplyFormat(tr, true, true);
	        }
	        if( 0 == gl3.UpdateThemeIDs(tr.Root) ) // if no err
	        {
	            gl3.ApplyFormat(tr, true, true);
	        }
	        if( 0 == gl4.UpdateThemeIDs(tr.Root) ) // if no err
	        {
	            gl4.ApplyFormat(tr, true, true);
	        }
	        if( 0 == gl5.UpdateThemeIDs(tr.Root) ) // if no err
	        {
	            gl5.ApplyFormat(tr, true, true);
	        }
	        if( 0 == gl6.UpdateThemeIDs(tr.Root) ) // if no err
	        {
	            gl6.ApplyFormat(tr, true, true);
	        }
    
		    GraphObject gobj1;
		    GraphObject gobj2;
		    GraphObject gobj3;
		    GraphObject gobj4;
		    GraphObject gobj5;
		    GraphObject gobj6;
			// Point to X axis label object which has name XB, and change its font
			gobj1 = gl1.GraphObjects("XB");
			gobj1.Label.Font.Size.nVal = 28;
			
			gobj2 = gl2.GraphObjects("XB");
			gobj2.Label.Font.Size.nVal = 28;
			
			gobj3 = gl3.GraphObjects("XB");
			gobj3.Label.Font.Size.nVal = 28;
			
			gobj4 = gl4.GraphObjects("XB");
			gobj4.Label.Font.Size.nVal = 28;
			
			gobj5 = gl5.GraphObjects("XB");
			gobj5.Label.Font.Size.nVal = 28;
			
			gobj6 = gl6.GraphObjects("XB");
			gobj6.Label.Font.Size.nVal = 28;
			
			// Point to Y axis label object which has name YL, and change its font
			gobj1 = gl1.GraphObjects("YL");
			gobj1.Label.Font.Size.nVal = 28;
			
			gobj2 = gl2.GraphObjects("YL");
			gobj2.Label.Font.Size.nVal = 28;
			
			gobj3 = gl3.GraphObjects("YL");
			gobj3.Label.Font.Size.nVal = 28;
			
			gobj4 = gl4.GraphObjects("YL");
			gobj4.Label.Font.Size.nVal = 28;
			
			gobj5 = gl5.GraphObjects("YL");
			gobj5.Label.Font.Size.nVal = 28;
			
			gobj6 = gl6.GraphObjects("YL");
			gobj6.Label.Font.Size.nVal = 28;
			
			// Point to Legend label object which has name Legend, and change its font
			gobj1 = gl1.GraphObjects("Legend");
			gobj1.Label.Font.Size.nVal = 28;
			
			gobj2 = gl2.GraphObjects("Legend");
			gobj2.Label.Font.Size.nVal = 28;
			
			gobj3 = gl3.GraphObjects("Legend");
			gobj3.Label.Font.Size.nVal = 28;
			
			gobj4 = gl4.GraphObjects("Legend");
			gobj4.Label.Font.Size.nVal = 28;
			
			gobj5 = gl5.GraphObjects("Legend");
			gobj5.Label.Font.Size.nVal = 28;
			
			gobj6 = gl6.GraphObjects("Legend");
			gobj6.Label.Font.Size.nVal = 28;
	
	
			foreach( GraphPage gp in Project.GraphPages )
				{
					gp.LT_execute("layer.x.label.pt=28"); // set X axis tick label font size to 28 in layer 1
					gp.LT_execute("layer.y.label.pt=28"); // set X axis tick label font size to 28 in layer 1
				    out_str(gp.GetName());
				}
			 
			// Rescale layer
			gl1.Rescale();
			gl2.Rescale();
			gl3.Rescale();
			gl4.Rescale();
			gl5.Rescale();
			gl6.Rescale();	
			
			NumLayers++;
							//if(WPtarget.AddLayer(Layr)<0)
							//{
							//	goto ErrorExit;
							//}
						}
					}
				}
				
			GraphLayer lay("Graph1");
			int bb = lay.GroupPlots(1, 7);
				if(NumLayers>0)
				{
					if(WksEmpty.IsValid()==true)
					{
						WksEmpty.Destroy();
					}
					string strWbk=WPtarget.GetName();
					//SetDataDisplayText("Worksheets Collected in  "+strWbk);
					return 0;
				}
ErrorExit:		WPtarget.Destroy();
			}
		}

It is not optimized i know ( but can somebody help me with my case?

Penn

China
644 Posts

Posted - 11/10/2011 :  10:39:22 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

You can just add one more data plot to the graph layer. See the sample below:

void testtwoplot()
{
	Worksheet wks = Project.ActiveLayer();
	DataRange dr1;
	DataRange dr2;
	
	dr1.Add(wks, 0, "X");
	dr1.Add(wks, 1, "Y");
	dr2.Add(wks, 0, "X");
	dr2.Add(wks, 2, "Y");
	
	GraphPage gp;
	gp.Create("origin", CREATE_HIDDEN);
	GraphLayer gl = gp.Layers();
	gl.AddPlot(dr1, IDM_PLOT_LINESYMB);
	gl.AddPlot(dr2, IDM_PLOT_LINESYMB);  // add the second plot
 
	gl.Rescale();
	gp.Refresh();
}


Penn
Go to Top of Page

olsy

29 Posts

Posted - 11/11/2011 :  04:36:58 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
the thing is that i´ve already plotted all separated graphs...is it the way just to put them now together after?
Go to Top of Page

Penn

China
644 Posts

Posted - 11/11/2011 :  05:07:47 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

You can try the merge_graph X-Function. You can use the LT_execute function to call LabTalk command in Origin C code.

Penn
Go to Top of Page

bostonryan72

USA
1 Posts

Posted - 11/13/2011 :  8:11:36 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Brilliant Ideas dude!

Free Life Insurance Online Quotes
Go to Top of Page

olsy

29 Posts

Posted - 11/15/2011 :  03:40:03 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I can´t find the merge_graph function which can put plots together in one layer...now they are still two in one window..

what i want to do is to have first and seventh graphs in the same axes as shown on the picture...actually it suppose to be like first, 7th, 13rd and so on together...and 2nd, 8th, 14th....and 3rd with 9th, 14th...

how can i do this?
Go to Top of Page

Penn

China
644 Posts

Posted - 11/15/2011 :  9:41:14 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Please note that merge_graph is an X-Function, but not Origin C function. However, you can call X-Function from Origin C code. The following is an simple example on how to call merge_graph. I have assume that there are two graphs, named graph1 and graph2, and then merge graph1 and graph2 into one graph.

void my_merge_graph()
{
	string strCmd = "merge_graph option:=specified ";  // merge specified graphs
	strCmd += "graphs:=graph1|graph2 ";  // merge graph1 and graph2
	strCmd += "keep:=0 ";  // after merge, do not keep the source graphs
	strCmd += "row:=1 col:=1";  // two merged graphs will be arranged by 1x1
	LT_execute(strCmd);  // execute this X-Function with the settings
}

Hope it can help.

Penn
Go to Top of Page

olsy

29 Posts

Posted - 11/16/2011 :  10:04:16 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks, Penn!
this i figure out but the problem is now that i´m getting something like:


is it any way to order the Y-axis? and add also the legend for the second graph?
Go to Top of Page

Penn

China
644 Posts

Posted - 11/16/2011 :  9:46:23 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

You can use another X-Function, legendupdate, to update the legend. About the axis, you can see that there are two graph layers in the new graph, so, you need to link one layer to another, see Linking Layers.

However, I think there should be a better solution. For example, I can get the data range from the two source graphs, which you want to merge, and then use the data range to make a new graph, and then delete the two source graphs. Here is the example code, in which I assume the two source graphs are Graph1 and Graph2.

void new_plot()
{
	GraphPage gp1("Graph1");  // graph1
	GraphPage gp2("Graph2");  // graph2
	
	GraphLayer gl1 = gp1.Layers(0);  // first layer in graph1
	GraphLayer gl2 = gp2.Layers(0);  // first layer in graph2
	
	DataPlot dp1 = gl1.DataPlots(0);  // first data plot in graph1
	DataPlot dp2 = gl2.DataPlots(0);  // first data plot in graph2

	XYRange xy1, xy2;
	dp1.GetDataRange(xy1);  // get XY data range
	dp2.GetDataRange(xy2);
	
	GraphPage gp;
	gp.Create("Origin", CREATE_HIDDEN);  // create a new graph
	GraphLayer gl = gp.Layers();
	gl.AddPlot(xy1, IDM_PLOT_LINESYMB);  // add data plot to the layer
	gl.AddPlot(xy2, IDM_PLOT_LINESYMB);
	gl.Rescale();
	
	gp1.Destroy();  // destroy graph1
	gp2.Destroy();  // destroy graph2
}


Penn
Go to Top of Page

olsy

29 Posts

Posted - 11/17/2011 :  08:09:38 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks, Penn! It works perfect!
But what i also want to do is:
i have N of this Graphs, and i need to add each seventh data plot to the first graph, eighth data plot to a second and so on....
For example, if i have 30 Graphs it should be like first, seventh, 13th, 19th, 25th together;
2nd, 8th, 14th, 20th, 26th together;
3rd, 9th, 15th, 21st, 27th together and so on till 6th, 12, 18th, 24th, 30th.
so i have 6 basic Graphs for different parameters.
i´ve tried with simple loop but it doesn´t understand the name of the Graph with variable...
Is it any way to do it?
and how i can group them? with simple gl.GroupPlots(0) it changes only the color but i would like to change also a symbol shape....
Go to Top of Page

Penn

China
644 Posts

Posted - 11/17/2011 :  9:49:25 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I do not really catch the meaning of "it doesn´t understand the name of the Graph with variable", could you please provide more details of the issue, or your code? About the group plots, please refer to Accessing Group Plots Format.

Penn
Go to Top of Page

olsy

29 Posts

Posted - 11/18/2011 :  03:40:34 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
sorry for my explanation:
int iGraphCount=Project.GraphPages.Count(); //Current number of graphs in project
        for (int i=1; i<=iGraphCount; i++)
        {
        k=i+6; 
	GraphPage gp1("Graph[i]");  // graph1
	GraphPage gp7("Graph[k]");  // graph2
	
	GraphLayer gl1 = gp1.Layers(0);  // first layer in graph1
	GraphLayer gl7 = gp7.Layers(0);  // first layer in graph2
	
	DataPlot dp1 = gl1.DataPlots(0);  // first data plot in graph1
	DataPlot dp7 = gl7.DataPlots(0);  // first data plot in graph2
	
	XYRange xy1, xy7;
	dp1.GetDataRange(xy1);  // get XY data range
	dp7.GetDataRange(xy7);
	
	GraphPage gp;
	gp.Create("Origin", CREATE_HIDDEN);  // create a new graph
	GraphLayer gl = gp.Layers();
	gl.AddPlot(xy1, IDM_PLOT_LINESYMB);  // add data plot to the layer
	gl.AddPlot(xy7, IDM_PLOT_LINESYMB);
	
	gl.Rescale();
	
	gp1.Destroy();  // destroy graph1
	gp7.Destroy();  // destroy graph2
	
	gl.GroupPlots(0);
	gl.LT_execute("legend");

like this it doesn´t work..is it any other way to do it?
Go to Top of Page

Penn

China
644 Posts

Posted - 11/20/2011 :  8:56:44 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I am afraid there are something wrong with the following two lines in your code.

	GraphPage gp1("Graph[i]");  // graph1
	GraphPage gp7("Graph[k]");  // graph2

In this way, it will try to get the graph named "Graph[i]" and "Graph[k]", but not "Graph1" and "Graph7" (suppose i=1). Please change to the following way, and then try again.

	GraphPage gp1("Graph" + i);  // graph1
	GraphPage gp7("Graph" + k);  // graph2


Penn
Go to Top of Page

olsy

29 Posts

Posted - 11/21/2011 :  3:42:14 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
thanks a lot Penn! works perfect )
now the question with the legend: can i somehow put the Long name of the column with some cells values from this column or it is not possible? I mean that i want to have for example

Sample PCBM
q 1
e 2
t 1
b 3

name of the graphs then should be PCBM1; PCBM2; PCBM3.

Is it possible?
Go to Top of Page

Penn

China
644 Posts

Posted - 11/23/2011 :  03:31:13 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

There is no direct way to do so. However, there will be one solution here.

1. Create a new user-defined label row in the source data worksheet.
2. Get the Long Name from the column for legend, and then concatenate with the number in this column.
3. Put the string from step 2 to the label row created in step 1.
4. Use the legend_update function to update the legend, by passing "@LD1" for the lpcszCustomFormat parameter.

Penn
Go to Top of Page

olsy

29 Posts

Posted - 12/02/2011 :  10:25:07 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you Penn! It works now.
But i have one more question:
after running this part of the program:

int iGraphCount=Project.GraphPages.Count();
//Current number of graphs in project
for (int b=1; b<=iGraphCount; b++)
{
int d=b+6;
GraphPage gp1("Graph"+b); // graph1
GraphPage gp7("Graph"+d); // graph2

GraphLayer glayer1 = gp1.Layers(0); // first layer in graph1
GraphLayer glayer7 = gp7.Layers(0); // first layer in graph2

DataPlot dplot1 = glayer1.DataPlots(0); // first data plot in graph1
DataPlot dplot7 = glayer7.DataPlots(0); // first data plot in graph2

XYRange xy1, xy7;
dplot1.GetDataRange(xy1); // get XY data range
dplot7.GetDataRange(xy7);

GraphPage gp;
gp.Create("Origin", CREATE_HIDDEN); // create a new graph
gp.SetName("Parameter"+i);
GraphLayer gl = gp.Layers();
gl.AddPlot(xy1, IDM_PLOT_LINESYMB); // add data plot to the layer
gl.AddPlot(xy7, IDM_PLOT_LINESYMB);

gp1.Destroy(); // delete the graph
gp7.Destroy(); // delete the graph
}

it does everything write but each time after red line it shows unknown error. Do you have any idea what it can be?

and one more question: is it possible to create an exe file for the program in Origin C? Do not to show everybody the code of the program...
Go to Top of Page

Penn

China
644 Posts

Posted - 12/04/2011 :  8:46:55 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I am afraid that I cannot reproduce the problem about "unknown error". Could you please show more details?

Origin C cannot create an exe file. However, to hide your source code from others, you can use preprocessed files, see this page for more information.

Penn
Go to Top of Page

olsy

29 Posts

Posted - 12/18/2011 :  3:23:17 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
it is very strange...i have this code:
	WorksheetPage wpSource2=Project.Pages(-1);
		if(wpSource2.IsValid()==true)
		{
			WorksheetPage WPtarget2;
			string strName2 = "PlotStat";
			strName2.TrimLeft();
			strName2.TrimRight();
			strName2.MakeLower();
			if(WPtarget2.Create("xxx",CREATE_HIDDEN)==true)
			{
				Worksheet WksEmpty2(WPtarget2.Layers(0));
				WksEmpty2.SetName("xxx"+strName2);
				int NumLayers2=0;
				foreach (Layer Layr2 in wpSource2.Layers)
				{
					Worksheet WksSearch2(Layr2);
					if(WksSearch2.IsValid()==true)
					{
						string strWksName2=WksSearch2.GetName();
						if(is_str_match_begin(strName2,strWksName2)==true)
						{
							
			Worksheet wksdata2(Layr2);				
			printf("%s \n",wksdata2.GetName());
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////			
	// Create a new graph
	// Create a curve from columns of the worksheet
	// Refer to columns by position number
    int nColl = wksdata2.GetNumCols();
	for (int o=6; o<=nColl;o++)
	{	
	Curve crvData(wksdata2, 1, o);
	// Create a new graph
	// Can replace default template with custom one if needed
	GraphPage gpg;
	gpg.Create( "Origin.OTP" );
	//gpg.SetName(wksdata2.GetName()); // rename the graph
	// Point to Layer 1 and plot the curve
	// Can change to point to different layer as needed
	GraphLayer gly = gpg.Layers( 0 );
	gly.AddPlot( crvData, IDM_PLOT_SCATTER );

     	DataPlot dplot = gly.DataPlots(0);
		//dplot.SetSymbol(12);   // set symbol shape: empty circle
		 
		Tree trFormat7;
		trFormat7.Root.Symbol.Size.nVal = 12; // set size: 12
		//trFormat7.Root.DropLines.Vertical.nVal = true;  // add vertical droplines
		if( 0 == dplot.UpdateThemeIDs(trFormat7.Root) )
		{
			dplot.ApplyFormat(trFormat7, true, true);
		}
 
		gly.Rescale();

   
	// Define error dataset and add to data plot
	Dataset dsErr( wksdata2, o+1);
	int	nPlotIndex = gly.AddErrBar( crvData, dsErr );
	if( -1 == nPlotIndex)
	{
		out_str( "Failed to add error bar data" );
		return 0;
	}
	DataPlot dp7;
	dp7 = gly.DataPlots(1);  // error bar
                    
                    Tree trFormat4;                  
                    //trFormat4.Root.Line.Color.nVal = SYSCOLOR_BLUE;  // set color
                    trFormat4.Root.Line.Width.dVal = 3.;     // set line width
                    
                    if(0 == dp7.UpdateThemeIDs(trFormat4.Root))
                        dp7.ApplyFormat(trFormat4, true, true);  // apply theme tree
	gly.Rescale();
	o=o+2;
	Tree tr5;
			tr5.Root.Symbol.Size.dVal = 12;
			if(0 == gly.UpdateThemeIDs(tr5.Root) )    
			{
			    bool bb = gly.ApplyFormat(tr5, true, true);    // apply theme tree
			}
	Tree trFormat1;
			// first turn on top-right axes with a separate ApplyFormat call
			trFormat1.Root.Axes.X.Ticks.TopTicks.show.nVal = 1;
			trFormat1.Root.Axes.Y.Ticks.RightTicks.show.nVal = 1;
			//assign node IDs to all nodes in trFormat, return number of errors
			int nErr1 = gly.UpdateThemeIDs( trFormat1.Root ) ;
			if(0 != nErr1)
				out_str("Fail to Update Theme IDs, theme tree has wrong structure");
			gly.ApplyFormat( trFormat1, true, true, true );
		 
			// then change settings can be done after needed axes are already turned on
			// Set the major minor ticks to In format for all XY axes
			trFormat1.Root.Axes.X.Ticks.TopTicks.Major.nVal = 3;
			trFormat1.Root.Axes.Y.Ticks.RightTicks.Major.nVal = 3;
			trFormat1.Root.Axes.X.Ticks.TopTicks.Minor.nVal = 3;
			trFormat1.Root.Axes.Y.Ticks.RightTicks.Minor.nVal = 3;
			nErr1 = gly.UpdateThemeIDs( trFormat1.Root ) ;
			if(0 != nErr1)
				out_str("Fail to Update Theme IDs, theme tree has wrong structure");
		 
			gly.ApplyFormat( trFormat1, true, true, true ); 

			
			GraphObject gobj11;
		    
			// Point to X axis label object which has name XB, and change its font
			gobj11 = gly.GraphObjects("XB");
			gobj11.Label.Font.Size.nVal = 32;
			// Point to Y axis label object which has name YL, and change its font
			gobj11 = gly.GraphObjects("YL");
			gobj11.Label.Font.Size.nVal = 32;		
					
			// Point to Legend label object which has name Legend, and change its font
			gobj11 = gly.GraphObjects("Legend");
			gobj11.Label.Font.Size.nVal = 28;
			
			gpg.LT_execute("layer.x.label.pt=28"); // set X axis tick label font size to 28 in layer 1
			gpg.LT_execute("layer.y.label.pt=28"); // set X axis tick label font size to 28 in layer 1
			
			//Rescale layer
			gly.Rescale();
	
vector<string> vS5;
	Dataset ds5("[Sun-Results.xls]The best", 2);
	ds5.GetStringArray(vS5, 0, 2);
	Worksheet wkks5("[Sun-Results.xls]The best");	
	string strr5, strs15, strr25, strs25;
	strr5.Format("\\l(1) ");
	strs15.Format(" %s",vS5[0]);
	strr25.Format("\\l(2) ");
	strs25.Format(" %s",vS5[1]);
	
	GraphObject goLegends5 = gly.GraphObjects("legend");
	if( goLegends5.IsValid() )
		goLegends5.Text = strr5 + wkks5.Columns(2).GetLongName()+ strs15; // replace the text
	}	
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////			
			NumLayers2++;
		}
					}
				}
				
ErrorExit2:		WPtarget2.Destroy();
			}
		}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
				 
////////////////////////////////////// Plot PARAMETERS///////////////////////////////////////////////////////////////////////////////////////////	//////////////////////////////////////////////////	

//CollectSheets
//Collects All Worksheets from the current Workbook with names beginning with "PlotParam" 

WorksheetPage wpSource=Project.Pages(-1);
		if(wpSource.IsValid()==true)
		{
			WorksheetPage WPtarget;
			string strName = "PlotParam";
			strName.TrimLeft();
			strName.TrimRight();
			strName.MakeLower();
			if(WPtarget.Create("xxx",CREATE_HIDDEN)==true)
			{
				Worksheet WksEmpty(WPtarget.Layers(0));
				WksEmpty.SetName("xxx"+strName);
				int NumLayers=0;
				foreach (Layer Layr in wpSource.Layers)
				{
					Worksheet WksSearch(Layr);
					if(WksSearch.IsValid()==true)
					{
						string strWksName=WksSearch.GetName();
						if(is_str_match_begin(strName,strWksName)==true)
						{
							
			Worksheet wksdata(Layr);				
			DataRange dr1;
		    DataRange dr2;
		    DataRange dr3;
		    DataRange dr4;
		    DataRange dr5;
		    DataRange dr6;
 
		    dr1.Add(wksdata, 1, "X");
		    dr1.Add(wksdata, 5, "Y");
		    dr2.Add(wksdata, 1, "X");
		    dr2.Add(wksdata, 6, "Y");
		    dr3.Add(wksdata, 1, "X");
		    dr3.Add(wksdata, 7, "Y");
		    dr4.Add(wksdata, 1, "X");
		    dr4.Add(wksdata, 8, "Y");
		    dr5.Add(wksdata, 1, "X");
		    dr5.Add(wksdata, 9, "Y");
		    dr6.Add(wksdata, 1, "X");
		    dr6.Add(wksdata, 10, "Y");
		 
		    GraphPage gp1;
		    gp1.Create("origin", CREATE_HIDDEN);
		    GraphLayer gl1 = gp1.Layers();
		 
		    //GAP_GROUP_PLOTS is specified by default, so if data range has multiple plots, they will be grouped
		    gl1.AddPlot(dr1, IDM_PLOT_LINESYMB);
		    int 	nMode = ALM_CUSTOM; 
			bool 	bCreate = true; // true, if no legend will create one
			bool	bReconstruct = false; // true, if always delete the original legend and create a new one; false, not delete old one just update
			string 	strCustomMode = "@LN";  // use Column Units label as legend
		    legend_update(gl1,nMode, bCreate, bReconstruct, strCustomMode); // to update the legend loaded in from template			
		    gl1.Rescale();
		    gp1.SetShow();
		    
	
		    GraphPage gp2;
		    gp2.Create("origin", CREATE_HIDDEN);
		    GraphLayer gl2 = gp2.Layers();
		 
		    //GAP_GROUP_PLOTS is specified by default, so if data range has multiple plots, they will be grouped
		    gl2.AddPlot(dr2, IDM_PLOT_LINESYMB);
		 
		    gl2.Rescale();
		    legend_update(gl2,nMode, bCreate, bReconstruct, strCustomMode); // to update the legend loaded in from template
		    gp2.SetShow();
		
		    GraphPage gp3;
		    gp3.Create("origin", CREATE_HIDDEN);
		    GraphLayer gl3 = gp3.Layers();
		 
		    //GAP_GROUP_PLOTS is specified by default, so if data range has multiple plots, they will be grouped
		    gl3.AddPlot(dr3, IDM_PLOT_LINESYMB);
		 
		    gl3.Rescale();
		    legend_update(gl3,nMode, bCreate, bReconstruct, strCustomMode); // to update the legend loaded in from template
		    gp3.SetShow();
		        	
		    GraphPage gp4;
		    gp4.Create("origin", CREATE_HIDDEN);
		    GraphLayer gl4 = gp4.Layers();
		 
		    //GAP_GROUP_PLOTS is specified by default, so if data range has multiple plots, they will be grouped
		    gl4.AddPlot(dr4, IDM_PLOT_LINESYMB);
		 
		    gl4.Rescale();
		    legend_update(gl4,nMode, bCreate, bReconstruct, strCustomMode); // to update the legend loaded in from template
		    gp4.SetShow();
		    
		    GraphPage gp5;
		    gp5.Create("origin", CREATE_HIDDEN); 
		    GraphLayer gl5 = gp5.Layers();
		 
		    //GAP_GROUP_PLOTS is specified by default, so if data range has multiple plots, they will be grouped
		    gl5.AddPlot(dr5, IDM_PLOT_LINESYMB);
		 
		    gl5.Rescale();
		    legend_update(gl5,nMode, bCreate, bReconstruct, strCustomMode); // to update the legend loaded in from template
		    gp5.SetShow();
		    
		    GraphPage gp6;
		    gp6.Create("origin", CREATE_HIDDEN);
		    GraphLayer gl6 = gp6.Layers();
		 
		    //GAP_GROUP_PLOTS is specified by default, so if data range has multiple plots, they will be grouped
		    gl6.AddPlot(dr6, IDM_PLOT_LINESYMB);
		 
		    gl6.Rescale();
		    legend_update(gl6,nMode, bCreate, bReconstruct, strCustomMode); // to update the legend loaded in from template
		    gp6.SetShow();
  
    		NumLayers++;
		}
					}
				}

ErrorExit:		WPtarget.Destroy();
			}
		}
		
	int iGraphCount=Project.GraphPages.Count(); //Current number of graphs in project		
	for (int b=1; b<=iGraphCount; b++)
    {
    int d=b+6; 
	GraphPage gp1("Graph"+b);  // graph1
	GraphPage gp7("Graph"+d);  // graph2
	
	GraphLayer glayer1 = gp1.Layers(0);  // first layer in graph1
	GraphLayer glayer7 = gp7.Layers(0);  // first layer in graph2
	
	DataPlot dplot1 = glayer1.DataPlots(0);  // first data plot in graph1
	DataPlot dplot7 = glayer7.DataPlots(0);  // first data plot in graph2

	XYRange xy1, xy7;
	dplot1.GetDataRange(xy1);  // get XY data range
	dplot7.GetDataRange(xy7);
    
	GraphPage gp;
	gp.Create("Origin", CREATE_HIDDEN);  // create a new graph
	gp.SetName("Parameter"+b);
	GraphLayer gl = gp.Layers();
	gl.AddPlot(xy1, IDM_PLOT_LINESYMB);  // add data plot to the layer
	gl.AddPlot(xy7, IDM_PLOT_LINESYMB);
	
	gp1.Destroy(); // delete the graph
	gp7.Destroy(); // delete the graph
    
	vector<string> vS;
	Dataset ds("[Sun-Results.xls]The best", 2);
	ds.GetStringArray(vS, 0, 2);
	Worksheet wkks("[Sun-Results.xls]The best");	
	string strr, strs1, strr2, strs2;
	strr.Format("\\l(1) ");
	strs1.Format(" %s\n",vS[0]);
	strr2.Format("\\l(2) ");
	strs2.Format(" %s",vS[1]);
	gp.LT_execute(strr);
	GraphObject goLegends = gl.GraphObjects("legend");
	if( goLegends.IsValid() )
		goLegends.Text = strr + wkks.Columns(2).GetLongName()+ strs1 + strr2 + wkks.Columns(2).GetLongName() + strs2; // replace the text
		
	gl.GroupPlots(0);

	GroupPlot gplot = gl.Groups(0); // Get the first group in layer
			 
			// the Nester is an array of types of objects to do nested cycling in the group
			// four types of setting to do nested cycling in the group
			vector<int> vNester(3); 
			vNester[0] = 0;  // cycling line color in the group
			vNester[1] = 3;  // cycling symbol type in the group
			gplot.Increment.Nester.nVals = vNester;  // set Nester of the grouped plot 
			 
			// Put format settings to vector for 6 plots
			vector<int> vLineColor = {SYSCOLOR_BLUE, SYSCOLOR_RED, SYSCOLOR_OLIVE, SYSCOLOR_CYAN, SYSCOLOR_PURPLE, SYSCOLOR_PINK};
			vector<int> vSymbolShape = {1, 3, 5, 8, 2, 6};
					 
			Tree tr;
			tr.Root.Increment.LineColor.nVals = vLineColor;  // set line color to theme tree
			tr.Root.Increment.Shape.nVals = vSymbolShape;  // set symbol shape to theme tree
			tr.Root.Line.Width.dVal = 3;
			tr.Root.Symbol.Size.dVal = 12;
			
			if(0 == gplot.UpdateThemeIDs(tr.Root) )    
			{
			    bool bb = gplot.ApplyFormat(tr, true, true);    // apply theme tree
			}
			
			Tree trFormat;
			// first turn on top-right axes with a separate ApplyFormat call
			trFormat.Root.Axes.X.Ticks.TopTicks.show.nVal = 1;
			trFormat.Root.Axes.Y.Ticks.RightTicks.show.nVal = 1;
			//assign node IDs to all nodes in trFormat, return number of errors
			int nErr = gl.UpdateThemeIDs( trFormat.Root ) ;
			if(0 != nErr)
				out_str("Fail to Update Theme IDs, theme tree has wrong structure");
			gl.ApplyFormat( trFormat, true, true, true );
		 
			// then change settings can be done after needed axes are already turned on
			// Set the major minor ticks to In format for all XY axes
			trFormat.Root.Axes.X.Ticks.TopTicks.Major.nVal = 3;
			trFormat.Root.Axes.Y.Ticks.RightTicks.Major.nVal = 3;
			trFormat.Root.Axes.X.Ticks.TopTicks.Minor.nVal = 3;
			trFormat.Root.Axes.Y.Ticks.RightTicks.Minor.nVal = 3;
				
			nErr = gl.UpdateThemeIDs( trFormat.Root ) ;
			if(0 != nErr)
				out_str("Fail to Update Theme IDs, theme tree has wrong structure");
		 
			gl.ApplyFormat( trFormat, true, true, true ); 

			
			GraphObject gobj1;
		    
			// Point to X axis label object which has name XB, and change its font
			gobj1 = gl.GraphObjects("XB");
			gobj1.Label.Font.Size.nVal = 32;
			// Point to Y axis label object which has name YL, and change its font
			gobj1 = gl.GraphObjects("YL");
			gobj1.Label.Font.Size.nVal = 32;		
					
			// Point to Legend label object which has name Legend, and change its font
			gobj1 = gl.GraphObjects("Legend");
			gobj1.Label.Font.Size.nVal = 28;
			
			gp.LT_execute("layer.x.label.pt=28"); // set X axis tick label font size to 28 in layer 1
			gp.LT_execute("layer.y.label.pt=28"); // set X axis tick label font size to 28 in layer 1
			
			//Rescale layer
			gl.Rescale();      
    }


and it does plot first 12 graphs from the first part of the code and doesn´t do anything for other part ("Plot parameters"). What can be a reason?
Go to Top of Page

Penn

China
644 Posts

Posted - 12/19/2011 :  9:10:50 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Maybe you can debug the code by yourself. About how to debug the code, you can refer to the Debugger chapter in Code Builder Users Guide (open by menu Help: Programming: Code Builder).

Penn
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