2.2.4.33.5 Page::Create

Description

Create a new page using the supplied template. Supports both *.otw, *.otp as well as *.ogg, *.ogw files.

Syntax

BOOL Create( LPCSTR lpcszTemplate = NULL, int iOption = CREATE_DEFAULT_OPTIONS )

Parameters

lpcszTemplate
[input]The template file name from which to create the page
Pass "Origin" to use the default template, which can be origin.otp, origin.otw, or origin.otm depending on page type.
Pass NULL or an empty string to create without a template.
You may also pass a single window file name *.OGW, *.OGM and *.OGG. This will load the single window file provided
the type matches. For single windows, only CREATE_HIDDEN, CREATE_VISIBLE_SAME, CREATE_VISIBLE and CREATE_HIDDEN are relevant.
iOption
[input]Bitwise flag indicating how window should be created
Must be one of the following:
CREATE_TEMP = Create invisible and destroy on exit of scope.
CREATE_VISIBLE_SAME = Create with a visibility setting the same as what is stored in the template.
CREATE_VISIBLE = Create visible.
CREATE_HIDDEN = Create the page so it appears hidden in Proejct Explorer.
The following flags can be OR'ed with the above options:
CREATE_NO_REMOVE_TEMPLATEPICT = Do not remove template preview picture (graphic object) on loading.
CREATE_NO_GUI_ACCESS = Do not allow access from Project Explorer (only valid with CREATE_HIDDEN).
CREATE_EMPTY = Do not create any child object for page (i.e. do not create 1st layer).
CREATE_NO_DEFAULT_TEMPLATE = When template is specified but not found will fail creation and return FALSE,ignore if lpcszTemplate = NULL.
CREATE_KEEP_LAYER_NAMES = if not used, layer names will be reset, like for worksheets as Sheet1, Sheet2
CREATE_LOAD_1ST_LAYER_ONLY = only the first layer, for WorksheetPage, this is similar to Create of Worksheet class
CREATE_ENUM_EXIST_PAGE = Reset the short name, similar to LabTalk Win -t. If this bit is not set (default), the template's shortname will be kept but may subject to enumeration to avoid duplicate.
CREATE_ENUM_ADD_SEPARATOR = Add underscore between shortname and enumeration index, like Graph_1
CREATE_DEFAULT_OPTIONS = (CREATE_VISIBLE | CREATE_KEEP_LAYER_NAMES)

Return

Returns TRUE for success and FALSE for failure.

Examples

EX1

//Create a new workbook
void Page_Create_ex1()
{
	WorksheetPage wksPg;
	wksPg.Create("Origin");
}

EX2

int Page_Create_ex2(string strTemplateName = "Origin", BOOL bNoDefaultTemplate = TRUE)
{
    DWORD dwCntrl = CREATE_VISIBLE;
    if( bNoDefaultTemplate )
        dwCntrl |= CREATE_NO_DEFAULT_TEMPLATE;
        
    GraphPage gp;
    if( gp.Create(strTemplateName, dwCntrl) )
    {
        printf("Created a graph named %s\n", gp.GetName());
        if( !bNoDefaultTemplate && !strTemplateName.IsEmpty() )
            printf("Not sure if specified template %s is used, it may be missing and default was substituded\n", strTemplateName);
    }
    else
        printf("Template %s not found, can not create graph page\n", strTemplateName);
    return 0;
}

EX3

//This example loads an OGW file from the samples folder and set the newly 
//loaded page's short name. If you repeated run load_ogw, you will see the 
//new page name will start to enumerate as Test1, Test2 etc.

void Page_Create_ex3(BOOL bHideIt = false, string strNewName="Test")
{
	string strPath = GetAppPath(true);
	strPath += "Samples\Curve Fitting\Single Peak Fit.ogw";
	WorksheetPage page;
	page.Create(strPath, CREATE_HIDDEN);
	printf("%s\n", strPath);
	if(!page)
	{
		out_str("failed to be loaded");
		return;
	}
	page.Rename(strNewName);
	printf("is loaded, new Page Name is %s\n", page.GetName());
	if(!bHideIt)
		page.SetShow();
}

EX3

// use CREATE_EMPTY to create a page without 1st default layer
void Page_Create_ex3()
{
    WorksheetPage page;
    page.Create(NULL, CREATE_EMPTY);
    printf("Page Name is %s\n", page.GetName());    
    
    if(0 == page.Layers.Count())
    {    
        page.AddLayer("Test");
        
        int index = 0;
        foreach(Layer lay in page.Layers)
        {
            printf("layer %d named %s\n", index, lay.GetName());
            index++;
        }
    }
    else
        printf("Error, fail to create empty workbook\n");
    
    page.SetShow();
}

Remark

Create a new page using the supplied template and attach it to the Origin C object. The Create method should only be called from derived classes such as GraphPage, MatrixPage, WorksheetPage, and LayoutPage. A worksheet page created without a template will not have columns. A matrix page created without a template will have no MatrixObject. Creating a page without specifying a template is faster than when creating one from a template. Code to add needed columns and MatrixObjects can be subsequently executed.

See Also

PageBase::PageBase, Page::Page

Header to Include

origin.h