3.8.3 Accessing Pages

Version Info

Minimum Origin Version Required: Origin 8 SR1

Loop Over All Worksheets and Create Graphs

This example is capable of looping all the worksheets in the project, and then create a graph with the data in each worksheet. Also, all the graphs in the project are looping to print the information.

Before running the example, please execute the LabTalk script to import the required data.

doc -n;  // create a new project
win -c book1;  // delete book1
for(ii=1; ii<=12; ii++)  // import 12 files
{
	newbook;  // create a new workbook
	strNum$ = $(ii);  // file number
	if(ii<10)  // define file path according to file number
	{
		fname$ = system.path.program$ + "Samples\Curve Fitting\Step0" + strNum$ + ".dat";  // file path
		impASC options.sparklines:=0;  // import, turn sparkline off
	}
	else
	{
		fname$ = system.path.program$ + "Samples\Curve Fitting\Step" + strNum$ + ".dat";  // file path
		impASC options.sparklines:=0;  // import, turn sparkline off
	}
}
void accessing_pages()
{
	// loop all worksheet pages in project, add plots to graph
	foreach(WorksheetPage wp in Project.WorksheetPages)
	{
		if(wp.IsValid())
		{
			for(int iWks=0; iWks<wp.Layers.Count(); iWks++)  // all worksheets in worksheet page
			{
				Worksheet wks = wp.Layers(iWks);  // get worksheet
				if(wks.IsValid())
				{
					GraphPage gp;
					gp.Create("Origin");  // create graph page
					gp.SetName(wp.GetName()+"_"+wks.GetName());  // set graph page name
					GraphLayer gl = gp.Layers(0);  // get graph layer in graph page
					
					// loop over columns in worksheet and add plots to graph layer
					for(int iCol=1; iCol<wks.GetNumCols(); iCol+=2)
					{
						DataRange dr;
						dr.Add(wks, iCol, "X");
						dr.Add(wks, iCol+1, "Y");  // data range
						gl.AddPlot(dr, IDM_PLOT_LINE);  // add line plot
					}
					gl.GroupPlots(0);  // group all plots in the graph layer
					gl.Rescale();  // rescale graph layer
				}
			}
		}
	}
	
	// number of graph pages in project
	printf("There are %d graph pages in the project.\n", Project.GraphPages.Count());
	
	// loop all graph pages in project and print their information
	for(int iGP=0; iGP<Project.GraphPages.Count(); iGP++)
	{
		GraphPage gp = Project.GraphPages(iGP);  // get graph page
		if(gp.IsValid())
		{
			printf("Graph Page %d:\n", iGP);  // index of graph page
			printf("\tName is: %s\n", gp.GetName());  // name of graph page
			printf("\tNumber of Graph Layers: %d\n", gp.Layers.Count());  // number of graph layers in graph page
			
			// loop all graph layers in graph page
			for(int iGL=0; iGL<gp.Layers.Count(); iGL++)
			{
				// print the nubmer of plots in the iGLth graph layer
				printf("\tNumber of Plots in Graph Layer %d is: %d\n", iGL, gp.Layers(iGL).DataPlots.Count());
			}
		}
	}
}

Loop Over All Notes and Print Out Contents

// This function prints out the paths and contents of all the notes of current project. 
// If a folder location is input as an argument, only notes of that folder is printed. 
void accessing_notes(string FdName = "")
{
	foreach ( Note nte in Project.Notes)
	{
		if(nte.GetFolder().GetPath() == FdName || FdName == "" )
		{
		printf("The location of %s: %s\n", nte.GetName(), nte.GetFolder().GetPath());
		printf("The content of %s: %s\n\n" ,nte.GetName(), nte.Text);
		}
	}
}