I'm a complete newbie to scripting in QCad.
I want to write a script which enables the User to insert lines at coordinates he specifies on the cammand line or by a mouse click, just like in the default "Lines"-menu.
How can I produce a prompt in then command line from within the script and get the value of user input in my script?
Thank you
Reimund
Scripting: Adding Lines via Command line
Moderator: andrew
See: QCad2.1\scripts\input01.qs
------------
------------
------------
Code: Select all
/**
* Author: Andrew Mustun
*
* Draws a sine curve from parameters given by the user.
*/
function main() {
var doc; // current document
var view; // current document view
var line; // line to add
var i; // counter
var factor; // scaling factor
var lx = -1.0;
var ly = -1.0;
var x;
var y;
factor = inputData();
doc = new Document;
view = new View;
for (x=0.0; x<2*Math.PI; x+=Math.PI/50) {
print("x: " + x);
y = Math.sin(x);
print("y: " + y);
if (lx>=0.0) {
var line = new Line(doc, lx*factor.x, ly*factor.y,
x*factor.x, y*factor.y);
doc.addEntity(line);
}
lx = x;
ly = y;
}
view.redraw();
}
/**
* Presents a dialog to input an X and Y factor for the sine.
*/
function inputData() {
var dialog = new Dialog;
dialog.caption = "Factor for sine curve";
dialog.okButtonText = "OK";
dialog.cancelButtonText = "Abort";
var xfact = new LineEdit;
xfact.label = "X Factor: ";
xfact.text = "1";
dialog.add(xfact);
var yfact = new LineEdit;
yfact.label = "Y Factor: ";
yfact.text = "1";
dialog.add(yfact);
if (dialog.exec()) {
print("Factors: " + xfact.text + "/" + yfact.text);
}
var ret = new Vector(xfact.text, yfact.text);
return ret;
}