2.5.1.7 ProjectEvents ScriptProjectEvents-Script
Run ProjectEvents ScriptScript, Project events
You may want to define functions, perform routine tasks, or execute a set of commands, upon opening, closing, or saving your Origin project. In Origin, this is facilitated by a file named ProjectEvents.ogs that is attached to the Origin Project (OPJ) by default.
A template version of this file is shipped with Origin and is located in the EXE folder. This template file is attached to each new project. The file can be viewed and edited by opening Code Builder and expanding the Project node in the left panel.
Sections of ProjectEvents.ogs
The ProjectEvents.ogs file, by default, contains three sections that correspond to three distinct events associated with the project:
- AfterOpenDoc: This section will be executed immediately after the project is opened
- BeforeCloseDoc: This section will be executed before the project is closed
- BeforeSaveDoc: This section will be executed before the project is saved
Utilizing ProjectEvents.ogs
In order for this file and its contents to have an effect, a user needs to edit the file and save it in Code Builder, and then save the project. The next time the project is opened, the script code contained in this attached OGS file will be executed upon the specified event (given by the pre-defined section name).
For example, if a user defines a new function in the [AfterOpenDoc] section of ProjectEvents.ogs, saves it (in Code Builder), and then saves the project in Origin, that function will be available (if defined to be global) for use any time the project is re-opened. To make the function available in the current session place the cursor (in Code Builder) on the section name to execute, select the Debug drop-down menu, and select the Execute Current Section option. Then in the Origin Script Window, issuing the list a command will confirm that the new function appears and is available for use in the project.
A brief tutorial in the Functions demonstrates the value of ProjectEvents.ogs when used in conjunction with LabTalk's dataset-based functions.
| You can add your own sections to this OGS file to save custom routines or project-specific script code. Such sections will not be event-driven, but can be accessed by name from any place that LabTalk script can be executed. For example, if you add a section to this file named [MyScript], the code in that section can be executed after opening the project by issuing this command from the script window:
run.section(projectevents,myscript);
|
A ProjectEvents.ogs script can also be made to run by opening the associated Origin Project (OPJ) from a command console external to Origin.
|