11.2.7 Accessing Internal Origin Objects by Origin C

Summary

Internal Origin objects (such as Project Explorer folders, Origin windows (pages), layers, plots, graphic objects, data sets, etc.) are accessed using Origin C classes. To access or programmatically control an internal Origin object, you must attach it to an Origin C object.

To attach something to an internal Origin object you must first "find" it using the properties, methods, and collections of a container class. Common container classes include the Project, Folder, Page, GraphPage, Layer, GraphLayer, Worksheet, MatrixLayer, and Collection classes. Once found, an internal Origin object can easily be attached to an Origin C object of the appropriate type.

The internal Origin object is then programmatically controlled by manipulating the class methods and properties of the attached Origin C object. The objective of this tutorial is to demonstrate how to find particular internal Origin objects, attach things to those objects, and access the objects by manipulating the methods and properties of the attached Origin C objects.

Minimum Origin Version Required: Origin 8.1 SR1

What you will learn

This tutorial will show you how to:

  • Access Worksheet Related Objects
  • Access Graph Related Objects

Accessing Worksheet Related Objects

Familiarity with the Origin C Project class (Project.h), the Collection class (Collection.h), and the Folder class (Folder.h), is valuable when attempting to understand how to find particular internal Origin Objects. Users may find it helpful to preview these classes in the Origin C Reference: Classes book of Origin C Help or in the above header files located in the ..\Origin\OriginC\system subfolder.

To begin this tutorial:

  1. Download this zip file, extract it.
  2. On the Standard toolbar, click the New Project button Button New.png.
  3. On the Standard toolbar, click the Code Builder button Button Code Builder.png.
  4. On the Code Builder menu, select File: New Workspace.
  5. On the Code Builder menu, click the Open button Button Open.png.
  6. Open the unzipped folder created at step 1, browse to the \Origin C Examples\Programming Guide\Introduction to Accessing Origin Objects folder in the Origin software directory, select AccessWorksheetObjectsTutorial.c, check the Add to Workspace check box and click Open.
  7. On the Code Builder toolbar, click the Rebuild All button Button Rebuild All.png. This compiles and links the file.
  8. On the Code Builder View menu, verify that the LabTalk Console (Command & Results) and the Local Variables windows are visible (the corresponding menu items should be checked).
  9. From the Code Builder menu, select Tools: Customize. Select the Toolbars tab and make sure that the Debug toolbar check box is selected.
  10. In Code Builder, activate AccessWorksheetObjectsTutorial.c.
  11. Near the top of the file, locate and click on the line:
PageBase pb;

You can position the cursor anywhere on the line.

  1. From the Code Builder menu, select Debug: Toggle Breakpoints. Alternately, press F9 or click the Toggle Breakpoint button Button Toggle Breakpoint.png on the Debug toolbar.

A brown circle is displayed in the gray margin to the left of the above line indicating that a Debug breakpoint has been set for that line.

  1. In the Code Builder workspace, activate the LabTalk Console (Command & Results window) and type in the following:
AccessWorksheetObjectsTutorial
  1. Press ENTER to execute the function.
AccessWorksheetObjectsTutorial 1.png
  1. On the Debug toolbar, press the Step Into button Button Step Into.png
  1. Press the Step Into button Button Step Into.pngrepeatedly, stopping to read the comments for each statement. Periodically stop and resize and/or reposition the Local Variables window to view the current run-time value of each variable.
AccessWorksheetObjectsTutorial 2.png

Accessing Graph Related Objects

  1. Return to the Origin workspace and, on the Standard toolbar, click the Open button Button Open.png.
  2. Locate the unzipped folder you created at step 1 of above section in this page. Browse to the \Origin C Examples\Programming Guide\Introduction to Accessing Origin Objects subfolder, select AccessGraphObjectsTutorial.OPJ, and click Open. You may be prompted to save changes to an untitled project. Click No and a worksheet and graph should open.
  3. From the Code Builder menu, select File: New Workspace. Click No when prompted to save workspace changes.
  4. In Code Builder, click the Open button Button Open.png.
  5. Locate the unzipped folder again. Browse to the Origin C Examples\Programming Guide\Introduction to Accessing Origin Objects subfolder, select AccessGraphObjectsTutorial.c, select the Add to Workspace check box, and click Open.
  6. Click the Rebuild All button Button Rebuild All.png to compile and link the file.
  7. On the Code Builder View menu, verify that the LabTalk Console (Command & Results) and the Local Variables windows are visible (the corresponding menu items should be checked).
  8. From the Code Builder menu, select Tools: Customize. Select the Toolbars tab and make sure that the Debug toolbar check box is selected.
  9. In the Code Builder workspace, activate AccessGraphObjectsTutorial.c.
  10. Near the top of the file locate and click on the line:
GraphPage gp;

You can position the cursor anywhere on the line.

  1. From the Code Builder menu, select Debug: Toggle Breakpoints. Alternately, press F9 or click the Toggle Breakpoint button Button Toggle Breakpoint.png on the Debug toolbar.

A brown circle is displayed in the gray margin to the left of the above line indicating that a Debug breakpoint has been set for that line.

  1. Activate the LabTalk Console (Command & Results window) in Code Builder and type the following:
AccessGraphObjectsTutorial
  1. Press ENTER to execute the function.
  1. On the Debug toolbar, press the Step Into button Button Step Into.png
  1. Press the Step Into button Button Step Into.pngrepeatedly, stopping to read the comments for each statement. Periodically stop and resize and/or reposition the Local Variables window to view the current run-time value of each variable.

This concludes the Internal Origin Objects tutorial.