2.12.1 Managing the Project

The DOCUMENT Command

Document is a native LabTalk command that lets you perform various operations related to the Origin Project. The syntax for the document command is

document -option value;

Notes:

  • value is not applicable for some options and is left out of the command
  • For additional capabilities please see the Doc (Object).

Internally, Origin updates a property that indicates when a project has been modified. Attempting to Open a project when the current project has been modified normally triggers a prompt to Save the current project. The document command has options to control this property.

Start a New Project

// WARNING! This will turn off the Save project prompt
document -s; 
// ''doc'' is short for ''document'' and ''n'' is short for ''new''
doc -n;

Open/Save a project

Use the doc -o command to open a project and the save command to save it.

// Open an Origin Project file
string fname$ = SYSTEM.PATH.PROGRAM$ + "Origin.opj";
doc -o %(fname$);   // Abbreviation of ''document -open''
// Make some changes
%(Data1,1) = data(0,100);
%(Data1,2) = 100 * uniform(101);
// Save the project with a new name in new location
fname$ = SYSTEM.PATH.APPDATA$ + "My Project.opj";
save %(fname$);

Append projects

Continuing with the previous script, we can Append other project file(s). Origin supports only one project file at a time so the existing project plus the appended project become the new project.

// Append an Origin Project file to the current file
fname$ = SYSTEM.PATH.PROGRAM$ + "Origin.opj";
doc -a %(fname$); // Abbreviation of ''document -append''
// Save the current project - which is still ''My Project.opj''
save;
// Save the current project with a new name to a new location
save C:\Data Files\working.opj;

Save/Load Child Windows

In Origin, a child window - such as a graph, workbook, matrix or Excel book - can be saved as a single file. Append can be used to add the file to another project. The appropriate extension is added automatically for Workbook, Matrix and Graph whereas you must specify .XLS for Excel windows.

// The save command acts on the active window
save -i C:\Data\MyBook;

Append can be used to load Child Window Types :

// Workbook(*.OGW), Matrix(*.OGM), Graph(*.OGG), Excel(*.XLS)
dlgfile group:=*.ogg; 
// fname is the string variable set by the dlgfile X-Function
doc -a %(fname$);

For Excel, you can specify that an Excel file should be imported rather than opened as Excel

doc -ai "C:\Data\Excel\Current Data.xls";

Notes windows are a special case with special option switch:

// Save notes window named Notes1
save -n Notes1 C:\Data\Notes\Today.TXT; 
// Read text file into notes window named MyNotes
open -n C:\Data\Notes\Today.txt MyNotes;

Saving External Excel Book

This is introduced in Origin 8.1, to allow an externally linked Excel book to be saved using its current file name:

save -i;

Refresh Windows

You can refresh windows with the following command:

doc -u;

Project Explorer X-Functions

The following X-Functions provide DOS-like commands to create, delete and navigate through the subfolders of the project:

Name Brief Description
pe_dir

Show the contents of the active folder

pe_cd

Change to another folder

pe_move

Move a Folder or Window

pe_path

Report the current path

pe_rename

Rename a Folder or Window

pe_mkdir

Create a Folder

pe_rmdir

Delete a Folder

In this example :

doc -s;                      // Clear Origin's 'dirty' flag
doc -n;                      // Start a new project
pe_cd /;                     // Go to the top level
pe_mkdir "Test Subjects";    // Create a folder
pe_cd "Test Subjects";       // Navigate to that folder
pe_mkdir "Trials";           // Create a sub-folder
pe_mkdir "Results";          //  and another
pe_cd /;                     // Return to the top level
pe_mkdir "Control Subjects"; // Create another folder
pe_cd "Control Subjects";    // Navigate to that folder
pe_mkdir "Trials";           // Create a sub-folder
pe_mkdir "Results";          //  and another
pe_cd /;                     // Return to the top level
pe_mkdir "Comparison";       // Create a folder

we create a folder structure that looks like this in Project explorer :
PE TREE.png

Note that if you have Open in Subfolder enabled in Preference: Options : [Open/Close] then you will have an additional folder named Folder1.