Managing Project

Version Info

Minimum Origin Version Required: Origin 8 SR1

Customize Project Explorer

This example is used to customize the structure of Project Explorer.

void project_explorer()
{
        Project pro;
        if(!pro.Open())  // create a new project
        {
                out_str("Failed to create a new project!\n");
                return;
        }
        
        Folder fldRoot = pro.RootFolder;  // get root folder
        foreach(Folder subfld in fldRoot.Subfolders)  // if subfolder exists, delete it
        {
                fldRoot.RemoveSubFolder(subfld.GetName());
        }
        
        Folder fldSubL1_1 = fldRoot.AddSubfolder("Test Subjects");  // level 1 first subfolder
        Folder fldSubL2_11 = fldSubL1_1.AddSubfolder("Trials");  // level 2 subfolder, in level 1 first subfolder
        Folder fldSubL2_12 = fldSubL1_1.AddSubfolder("Results");  // level 2 subfolder, in level 1 first subfolder
        
        Folder fldSubL1_2 = fldRoot.AddSubfolder("Control Subjects");  // level 1 second subfolder 
        Folder fldSubL2_21 = fldSubL1_2.AddSubfolder("Trials");  // level 2 subfolder, in level 1 second subfolder
        Folder fldSubL2_22 = fldSubL1_2.AddSubfolder("Results");  // level 2 subfolder, in level 1 second subfolder
        
        Folder fldSubL1_3 = fldRoot.AddSubfolder("Comparison");  // level 1 third subfolder 
}

Project Operation

The following example is capable of managing project, including creating a new project, appending an existing project to another project, saving a active folder as project, saving a worksheet as template, and saving the project with a new name.

void managing_project()
{
        Project pro;
        if(!pro.Open())  // create a new project
        {
                out_str("Failed to create a new project!\n");
                return;
        }
        
        // append the existing project to the new project
        string strAppendPath = GetAppPath(true) + "Samples\\Graphing\\OffsetY.opj";
        if(!pro.Open(strAppendPath, OPJ_OPEN_APPEND_NEW_FOLDER))
        {
                out_str("Failed to append project!\n");
                return;
        }
        
        // save folder as project, worksheet as template with data and storage
        string strFolder = "/Folder1/OffsetY";  // folder path
        Folder fld(strFolder);
        if(fld.IsValid())  // if the folder exists
        {
                if(!fld.Activate())  // activate the folder
                {
                        out_str("Failed to activate the folder!\n");
                        return;
                }
                
                // path of the folder project to be saved
                string strSaveFolderPath = GetAppPath(false) + "OffsetYFolder.opj";
                
                // save the folder as project with subfolders and attached files
                if(fld.SaveAsProject(strSaveFolderPath, SFC_INCLUDE_SUBFOLDERS | SFC_INCLUDE_ATTACHED_FILES))
                        out_str("Save the folder as project successfully!\n");
                
                // loop pages in the folder and save worksheet as template
                for(int iPage; iPage<fld.Pages.Count(); iPage++)
                {
                        PageBase pg = fld.Pages(iPage);
            if(EXIST_WKS != pg.GetType())  // if the page is workbook
                continue;
            WorksheetPage wp = pg;
            Worksheet wks = wp.Layers(0);  // get first worksheet in the workbook
                        if(wks)
                        {
                                // save the worksheet as template with data and storage
                                if(wks.SaveAs(GetAppPath(false) + wks.GetName(), OOSAS_DATA | OOSAS_STORAGE))
                                        out_str("Save as worksheet template successfully!\n");

                        }
                        else
                                out_str("Not a valid worksheet page!\n");
                }

        }
        
        // path of the new project
        string strNewPath = GetAppPath(false) + "MyNewProject.opj";
        if(pro.Save(strNewPath))  // save the project as a new project
                out_str("Succeed to save the new project!\n");
}