1.9.3 Accessing Pages

Pages in Origin consist of workbooks, matrixbooks and graphs, and are the core objects in a project. Origin C allows you to access a page by name or by index, or access all instances of a particular page type in the current project using the foreach statement.

Access a Page by Name and Index

All pages have names, which can be used to access them, as in the following example:

// Access a page by its name
GraphPage gp1("Graph1");	

// Access a page by its zero based index
GraphPage gp2 = Project.GraphPages(0); // 0 for first page

Get the Active Page and Layer

In a workbook page, a layer is a worksheet; in a graph page, a layer is a pair of axes; in a matrix page, a layer is a matrixsheet.

If you want to access the page associated with a particular layer, such as the active layer, it can be done with the Layer::GetPage method:

// get active layer
GraphLayer gl = Project.ActiveLayer();

// get active page from layer
GraphPage gp = gl.GetPage();

Activate One Page

If want to activate a window, you can use PageBase::SetShow(PAGE_ACTIVATE) to cause the window to be activated.

// attach to a graph window named Graph2
GraphPage gp( "Graph2" ); 

// set the window to be active
gp.SetShow( PAGE_ACTIVATE );

Using foreach

The foreach statement simplifies the process of looping through all the items in a collection. The project contains all the pages in various collections.

// Loop through all workbook pages in the current project
// and output the name of each page.
foreach( WorksheetPage wksPage in Project.WorksheetPages )
{
    out_str(wksPage.GetName());
}
// Loop through all matrixbook pages in the current project
// and output the name of each page.
foreach( MatrixPage matPage in Project.MatrixPages )
{
    out_str(matPage.GetName());
}
// Loop through all graph pages in the current project
// and output the name of each page.
foreach( GraphPage gp in Project.GraphPages )
{
    out_str(gp.GetName());
}
// Loop through all pages in the current project
// and output the name of each page.
foreach( PageBase pg in Project.Pages )
{
    out_str(pg.GetName());
}