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 from the tool menu on the left side of the project window -->Button Text Tool.png
  2. Now click in the open space to the right of the two empty columns of the blank worksheet in the Book1 window. This will open a text box. Type "Hello" in the text box and click outside the box--you have now created a label for the button.
  3. Now hold down the ALT key while double-clicking on the text that you just created. A window called Programming Control will appear.
  4. Not that there is an Object Name in the upper left of the dialog. Change this to Greeting.
  5. In the lower text box of the Programming Control window, enter our script:
    type -b "Hello World";
  6. Also in the Programming Control window, in the Script, Run After box, 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 which exists only in the Classic Script Window, this button and the script it runs will be saved when you save your Origin project.

The script behind any graphic object an be run using its name and the run method. Open the Command 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;