2.14.2 Getting Points from Graph

Any of the Tools in the Origin Tools Toolbar can be initiated from script, but three can be linked to macros and programmed to do more.

To program tools, define the pointproc macro to execute appropriate code. The pointproc macro runs when the user double-clicks or single-clicks and presses the Enter key.

Screen Reader

This script puts a label on a graph using the Screen Reader tool.

dotool 2;  // Start the Screen Reader Tool
dotool -d; // Allow a single click to act as double click
// Here we define our '''pointproc''' macro
def pointproc {
    label -a x y -n MyLabel Hello;
    dotool 0;  // Reset the tool to Pointer
    done = 1;  // Set the variable to allow infinite loop to end
}
// Script does not stop when using a tool, 
// so further execution needs to be prevented.
// This infinite loop waits for the user to select the point
for( done = 0 ; done == 0; ) sec -p .1; 
// A .1 second delay gives our loop something to do:
type Continuing script ...; 
// Once the macro has run, our infinite loop is released

Data Reader

The Data Reader tool is similar to the Screen Reader, but the cursor locks on to actual data points. If defined, a quittoolbox macro runs if user presses Esc key or clicks the Pointer Tool to stop the Data Reader.

This example assumes a graph window is active and expects the user to select three points on their graph.

@global = 1;
dataset dsx, dsy;  // Create two datasets to hold the X and Y values
dotool 3;          // Start the tool
// Define the macro that runs for each point selection
def pointproc {
    dsx[count] = x;  // Get the X coordinate
    dsy[count] = y;  // Get the Y coordinate
    count++;         // Increment count
    if(count == 4) dotool 0;  // Check to see if we have three points
    else type -a Select next point;
}
// Define a macro that runs if user presses Esc key, 
// or clicks the Pointer Tool:
def quittoolbox {
    // Error : Not enough points
    if(count < 4) ty -b You did not specify three datapoints;  
    else
    {
        draw -l {dsx[1],dsy[1],dsx[2],dsy[2]};
        draw -l {dsx[2],dsy[2],dsx[3],dsy[3]};
        draw -l {dsx[3],dsy[3],dsx[1],dsy[1]};
        double ds12 = dsx[1]*dsy[2] - dsy[1]*dsx[2];
        double ds13 = dsy[1]*dsx[3] - dsx[1]*dsy[3];
        double ds23 = dsy[3]*dsx[2] - dsy[2]*dsx[3];
        area = abs(.5*(ds12 + ds13 + ds23));
        type -b Area is $(area);
    }
}
count = 1;  // Initial point
type DoubleClick your first point (or SingleClick and press Enter);

The following example allows user to select arbitrary number of points until Esc key is pressed or user clicks on the Pointer tool in the Tools toolbar.

@global = 1;
dataset dsx, dsy;  // Create two datasets to hold the X and Y values
dotool 3;          // Start the tool
// Define the macro that runs for each point selection
def pointproc {
    count++;         // Increment count
    dsx[count] = x;  // Get the X coordinate
    dsy[count] = y;  // Get the Y coordinate
}

// Define a macro that runs if user presses Esc key, 
// or clicks the Pointer Tool:
def quittoolbox {
   count=;
   for(int ii=1; ii<=count; ii++)
   {
      type $(ii), $(dsx[ii]), $(dsy[ii]);
   }
}
count = 0;  // Initial point
type "Click to select point, then press Enter";
type "Press Esc or click on Pointer tool to stop";

Pressing Enter key to select a point works more reliably than double-clicking on the point.

You can also use the getpts command to gather data values from a graph.

Data Selector

The Data Selector tool is used to set a Range for a dataset. A range is defined by a beginning row number (index) and an ending row. You can define multiple ranges in a dataset and Origin analysis routines will use these ranges as input, excluding data outside these ranges.

Here is a script that lets the user select a range on a graph.

    // Start the tool
    dotool 4;
    // Define macro that runs when user is done
    def pointproc {
        done = 1;
        dotool 0;
    }
    // Wait in a loop for user to finish by pressing ...
    // (1) Enter key or (2) double-clicking
    for( done = 0 ; done == 0 ; )
    {
        sec -p .1;
    }
    // Additional script will run once user completes tool.
    ty continuing ..;

When using the Regional Data Selector or the Regional Mask Tool you can hook into the quittoolbox macro which triggers when a user presses Esc key:

    // Start the Regional Data Selector tool with a graph active
    dotool 17;
    // Define macro that runs when user is done
    def quittoolbox {
        done = 1;
    }
    // Wait in a loop for user to finish by pressing ... 
    // (1) Esc key or (2) clicking Pointer tool:
    for( done = 0 ; done == 0 ; )
    {
        sec -p .1;
    }
    // Additional script will run once user completes tool.
    ty continuing ..;

And we can use an X-Function to find and use these ranges:

// Get the ranges into datasets
dataset dsB, dsE;
mks ob:=dsB oe:=dsE;
// For each range
for(idx = 1 ; idx <= dsB.GetSize() ; idx++ )
{
    // Get the integral under the curve for that range
    integ %C -b dsB[idx] -e dsE[idx];
    type Area of %C from $(dsB[idx]) to $(dsE[idx]) is $(integ.area);
}

List of Tools in Origin Tools Toolbar. Those in bold are useful in programming.

Tool Number Description
0

Pointer - The Pointer is the default condition for the mouse and makes the mouse act as a selector.

1

ZoomIn - A rectangular selection on a graph will rescale the axes to the rectangle. (Graph only)

2

Screen Reader - Reads the location of a point on a page.

3

Data Reader - Reads the location of a data point on a graph. (Graph only)

4

Data Selector - Sets a pair of Data Markers indicating a data range. (Graph only)

5

Draw Data - Allows user the draw data points on a graph. (Graph only)

6

Text - Allows text annotation to be added to a page.

7

Arrow - Allows arrow annotation to be added to a page.

8

Curved Line - Allows curved line annotation to be added to a page.

9

Line - Allows line annotation to be added to a page.

10

Rectangle - Allows rectangle annotation to be added to a page.

11

Circle - Allows circle annotation to be added to a page.

12

Closed Polygon - Allows closed polygon annotation to be added to a page.

13

Open Polygon - Allows open polygon annotation to be added to a page.

14

Closed Region - Allows closed region annotation to be added to a page.

15

Open Region - Allows open region annotation to be added to a page.

16

ZoomOut - Zooms out (one level) when clicking anywhere in a graph. (Graph only)

17

Regional Data Selector - Allows selection of a data range. (Graph only)

18

Regional Mask Tool - Allows masking a points in a data range. (Graph only)