Scripting: Adding Lines via Command line

Use this forum to ask questions about how to do things in QCAD 2.1/2.2.

Moderator: andrew

Scripting: Adding Lines via Command line

Postby rele » Thu Aug 09, 2007 1:57 pm

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
rele
Registered Member
 
Posts: 1
Joined: Thu Aug 09, 2007 1:54 pm

Postby michael » Sun Sep 16, 2007 3:09 pm

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;
}


------------
--
Do you CAD? - I do QCad.
QCad Professional Order Online now:
http://www.ribbonsoft.com/qcad_order.html
michael
Site Admin
 
Posts: 115
Joined: Sun Sep 16, 2007 2:14 pm
Location: Switzerland


Return to QCAD 2.1/2.2 'How Do I' Questions

Who is online

Users browsing this forum: No registered users and 0 guests