Tutorial: Skripte aus einer Datei ausführen

Inhaltsverzeichnis

 

Einleitung

Es kann schnell mühsam werden, Skripte in die Skript Shell von QCAD einzugeben. Sobald die Skripte etwas komplexer werden, können Sie sie stattdessen in eine Datei schreiben. Für prozedurale Skripte, die keine Interaktion erfordern, können Sie einfach eine Textdatei mit Aufrufen der QCAD API erstellen und das Skript mit Diverses > Entwicklung > Skript ausführen ausführen.

Beispiele

Funktionen plotten

Eine typische Aufgabe für ein Skript wäre es, eine mathematische Funktion zu zeichnen. Dieses Beispiel stellt eine Lissajous-Kurve dar.

Beachten Sie, dass die Zeilen, die mit // beginnen, Kommentare sind. Kommentare werden ignoriert und dienen lediglich der Erläuterung.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// constants:
a=7; b=6;
// phase angle:
phi=0.2*Math.PI;
// iteration step:
step=Math.PI/256;
// width of plot (amplitude in X):
w=100;
// height of plot (amplitude in Y):
h=100;

// array of x,y coordinates on the curve:
v=[];

// loop:
for (t=0.0; t<Math.PI*2; t+=step) {
    // compute next x,y coordinate:
    x = w * Math.sin(a*t + phi);
    y = h * Math.sin(b*t);

    // append coordinate to our array of coordinates:
    v.push([x,y]);
}

// add a spline to the drawing, using
// the computed coordinates as fit points:
addSpline(v, true);

// auto zoom:
autoZoom();