Page 1 of 1

[Solved] N line number increment

Posted: Sat Jan 30, 2021 6:11 pm
by Daniel4
Hello,
I am in the need of two variables that increment by 1, each time they are called up.
I am using the 'N' linenumber as as one of the variables.
I made another variable in the JS file, and called it eventnumber.
It does show in the post, but does not increment.
I have some screenshots attached for reference.

Thank you.
P.S. Sorry if these files are not well organized, or if I am missing out something that I should have included.

Running Windows 10, QCad/Cam version 3.25.2.4

Re: N line number increment

Posted: Mon Feb 01, 2021 1:56 pm
by andrew
You'd have to detect when [E] gets written and increment accordingly:

Code: Select all

GCode2AxisPT.prototype.writeBlockFromString = function(blockStrings) {
    if (isNull(blockStrings)) {
        return;
    }

    if (isString(blockStrings)) {
        blockStrings = [ blockStrings ];
    }

    // detect usage of [E]
    var incE = false;
    for (var i=0; i<blockStrings.length; i++) {
        // blockString
        // e.g. "[N] G01 [X] [Y]"
        var blockString = blockStrings[i];
        if (blockString.contains("[E]")) {
            // a block string contains variable [E], increment after writing
            incE = true;
        }
    }

    // write block strings:
    CamExporterV2.prototype.writeBlockFromString.call(this, blockStrings);

    if (incE) {
        this.eventNumber+=this.eventNumberIncrement;
    }
};
This is overly complicated and we will add a function to detect variable usage more easily. This will work with QCAD/CAM >= 3.25.2.11:

Code: Select all

GCode2AxisPT.prototype.variableUsed = function(id, value) {
    if (id==="E") {
        this.eventNumber+=this.eventNumberIncrement;
    }
};

Re: [Solved] N line number increment

Posted: Wed Feb 03, 2021 2:41 am
by Daniel4
Wow Andrew!
I have no idea how you did that. it works perfect, thanks!
I could have never figured that out.