Draw a graph with script in Xtt
In addition to drawing a graph in the Ge editor, it is also possible to to write a ge script
that draws the graph. The script can call Ge script functions to draw graphical elements in the
graph, but it also call also xtt script functions. This makes it possible to get information
from the database and adapt the graph to the current state.
The script graph is opened as an ordinary graph but the graph name is replaced by the script
name preceded by a '@', eg 'open graph @myscript'. Scripts are by default read from $pwr_exe
or $pwrp_exe, and for any other location the path should be added, eg 'open graph
@"$pwrp_login/myscript"'.
Example
A simple script that draws a rectangle and a push button
main()
int id;
float x1;
float y1;
float x2;
float y2;
float width;
float height;
SetDraw(0);
SetBackgroundColor(eDrawType_Color66);
# Draw rectangle
x1 = 1;
y1 = 1;
width = 18;
height = 5;
id = CreateRectangle(x1, y1, width, height);
SetObjectFillColor(id, eDrawType_Color74);
SetObjectFill(id, 1);
SetObjectBorder(id, 0);
# Draw pushbutton
x1 = 7.5;
y1 = 2;
x2 = 10.5;
y2 = 3.5;
id = CreateObject("pwr_buttontogglecenter", x1, y1, x2, y2);
SetObjectAttribute(id, "Text", "Toggle");
SetObjectAttribute(id, "ToggleDig.Attribute", "H1-Dv1.ActualValue##Boolean");
# Set graph size
SetGraphAttribute("x1", 20.0);
SetGraphAttribute("y1", 7.0);
SetDraw(1);
endmain