From Graphical Objects

Graphic Objects (text, lines and shapes) can be tied to events and contain script that runs on those events or by using the run method for those objects. Since graphical objects are attached to a page, they are saved in Templates, Window files and Project files.


Some of your scripts may be used so often that you would like to automate their execution by assigning one or more of them to a button on the Origin project's graphical-user interface (GUI). To do so, follow the steps below:

From a new open Origin project:

  1. Select the Text tool Button Text Tool.png from the Tools toolbar to the left side of the project window.
  2. Click on an open space on your graph or worksheet (on a worksheet, click in the gray area to the right of the last column). This will put you into edit mode. Type "Hello" in the text object and click outside the object. You have now created a label for the button.
  3. Hold down the ALT key while double-clicking on the text object that you just created. The object dialog opens to the Programming tab.
  4. Note that there is an object Name in the upper left of the dialog. Change this to Greeting.
  5. In the lower text box, enter this script:
    type -b "Hello World";
  6. From the Script Run After drop-down list, select Button Up, and click OK.
  7. You have now created a button that, when pressed, executes your script and prints "Hello World" in a pop-up window.

Unlike a text script that exists only in the Script Window, this button and the script that it runs will be saved when you save your Origin project.

The script behind any graphic object can be run using its name and the run method. Open the Script Window (Window: Script Window) and type:


and press Enter.


Here is a script that creates a vertical line on a graph that can be moved to report the interpolated value of your data at the X position represented by the line:

// Create a vertical line on our graph
draw -n MyCursor -l -v $(x1+(x2-x1)/2);
MyCursor.HMOVE = 1;               // Allow horizontal movement
MyCursor.color = color(orange);   // Change color to orange
MyCursor.linewidth = 3;           // Make line thicker
// Add a label to the graph
label -sl -a $(MyCursor.x) $(Y2+0.05*(Y2-Y1)) -n MyLabel $(%C(MyCursor.x));
// Assign a script to the line ..
MyCursor.script$="MyLabel.x = MyCursor.x;
MyLabel.y = Y2 + MyLabel.dy;
doc -uw;";
// .. and make the script run after the line is moved
MyCursor.Script = 2;

Other Objects

Any Graphical Object (text, lines and shapes) can have an attached script that runs when an event occurs.

In this example, a rectangle (named RECT) on a graph is set to have a script run when the rectangle is either Moved or Sized.

  1. Use the Rectangle tool on the Tools toolbar to draw a rectangle on a graph.
  2. Use the Back(data) tool on the Object Edit toolbar to push the rectangle behind the data.
  3. Hold down the Alt key and double-click on the rectangle to open Programming Control. Note that the objects name is Rect.
  4. Enter the following script:
    %B = %C;
    %A = xof(%B);
    dataset dsRect;
    dsRect = ((%A >= rect.x1) && (%A <= rect.x2) && 
              (%B >= rect.y3) && (%B <= rect.y1))?%B:0/0;
    stats dsRect;
    delete dsRect;
    type -a Mean of $(stats.mean);
  5. Choose the Moved or Sized event in the Script, Run After drop down list.
  6. Click OK.

When you Move or Resize this rectangle, the script calculates the mean of all the points within the rectangle and types the result to the Script Window. You can also define a Graphic Object range and run the script like:

GObject gobj = [Graph1]1!rect;