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:
type -b "Hello World";
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:
greeting.run()
and press Enter.
![]() | To delete the button, there are two ways:
|
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;
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.
%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);
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; gobj.run();