[Solved] N line number increment

Discussions around the CAM Add-On of QCAD.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Indicate the post processor used.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
Daniel4
Junior Member
Posts: 17
Joined: Sat Jan 30, 2021 5:34 pm
Location: Wisconsin

[Solved] N line number increment

Post by Daniel4 » Sat Jan 30, 2021 6:11 pm

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
Attachments
Test Post.dxf
(109.35 KiB) Downloaded 391 times
PT4.js
(826 Bytes) Downloaded 367 times
GCode2AxisPT.js
(10.81 KiB) Downloaded 376 times
Eventnumber screenshot.jpg
Eventnumber screenshot.jpg (30.66 KiB) Viewed 5461 times
Thisrapidmove screenshot.jpg
Thisrapidmove screenshot.jpg (43.39 KiB) Viewed 5461 times
Eventnumber does not increment.jpg
Eventnumber does not increment.jpg (59.1 KiB) Viewed 5461 times
Last edited by Daniel4 on Wed Feb 03, 2021 2:40 am, edited 1 time in total.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: N line number increment

Post by andrew » Mon Feb 01, 2021 1:56 pm

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

Daniel4
Junior Member
Posts: 17
Joined: Sat Jan 30, 2021 5:34 pm
Location: Wisconsin

Re: [Solved] N line number increment

Post by Daniel4 » Wed Feb 03, 2021 2:41 am

Wow Andrew!
I have no idea how you did that. it works perfect, thanks!
I could have never figured that out.

Post Reply

Return to “QCAD/CAM”