additions to the header

Discussions around the CAM Add-On of QCAD.

Moderator: andrew

jamby
Active Member
Posts: 25
Joined: Fri Jun 24, 2016 2:41 pm

additions to the header

Postby jamby » Sun Jun 25, 2017 4:35 pm

HI

Is it possible to add the "date & time" and "cutter dia." to the header?

Thanks
Jim

jamby
Active Member
Posts: 25
Joined: Fri Jun 24, 2016 2:41 pm

Re: additions to the header

Postby jamby » Sun Jun 25, 2017 4:37 pm

Opps it linux ubuntu 16.04 and qcadcam 3.17.1

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

Re: additions to the header

Postby andrew » Wed Jun 28, 2017 10:10 am

If you update to QCAD/CAM 3.17.2, you can use the following code (or similar) to output the date / time and tool diameter in the header:

Code: Select all

include("GCodeBase.js");

function MyGCode(cadDocumentInterface, camDocumentInterface) {
    GCodeBase.call(this, cadDocumentInterface, camDocumentInterface);

    this.decimals = 4;
    this.unit = RS.Millimeter;

    // register variable for date and time:
    this.dateTime = undefined;
    this.registerVariable("dateTime", "DATE_TIME", true, "",  0);

    this.header = [
        "( date/time: [DATE_TIME] )",
        "( tool dimater: [TD] )"
    ];
}

MyGCode.prototype = new GCodeBase();

MyGCode.displayName = "MyGCode";

MyGCode.prototype.writeFile = function(fileName) {
    // init date / time variable:
    var today = new Date();
    this.dateTime = formatDate(today, "dd/MMM/yyyy hh:mm:ss");

    GCodeBase.prototype.writeFile.call(this, fileName);
};


The function formatDate supports various formatting parameters.

jamby
Active Member
Posts: 25
Joined: Fri Jun 24, 2016 2:41 pm

Re: additions to the header

Postby jamby » Fri Jun 30, 2017 3:01 am

Thanks Andrew

Now I just have to understand how to call this file.


Jim

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

Re: additions to the header

Postby andrew » Fri Jun 30, 2017 7:17 am

That would be as follows:
- Save the attached ZIP file
- Extract the ZIP file
- Inside you can find a file called "MyGCode.js"
- Copy that file into the "postprocessors" directory of your QCAD/CAM installation (e.g. "/home/me/opt/qcadcam-3.17.2-pro-linux-x86_64/postprocessors")

MyGCode.js is a text file. You can edit it with any plain text editor of your choice (e.g. gedit).
Attachments
MyGCode.zip
(541 Bytes) Downloaded 38 times

jamby
Active Member
Posts: 25
Joined: Fri Jun 24, 2016 2:41 pm

Re: additions to the header

Postby jamby » Sun Jul 02, 2017 4:48 pm

Andrew

Ubuntu 16.04
qcadcam 3.17.2
Emc2IN.js

The cutter dia. TD worked as soon as I loaded 3.17.2 However adding the MyGCode.js didn't get DATE_TIME to work. So I changed the include statment at the top of Emc2.js to read 'include("MyGCode.js")' and it still is not working.

Any idea what I am doing wrong?

include("Emc2.js");

Code: Select all

/**
 * Configuration for EMC2 controllers.
 * Output in Inches.
 */
function Emc2IN(cadDocumentInterface, camDocumentInterface) {
    Emc2.call(this, cadDocumentInterface, camDocumentInterface);

    this.unit = RS.Inch;

    // G20: Inch
    // G64 P#: Tolerance. Fine tune system for best compromise between speed and accuracy
    this.header = [
        "%",
        "(FILE PATH [FILEPATH])",
        "( date/time: [DATE_TIME] )",
        "(CUTTER DIA. [TD])",
        "G20",
        "G64 P0.025"
    ];
}


Thanks
Jim

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

Re: additions to the header

Postby andrew » Mon Jul 03, 2017 8:01 am

jamby wrote:The cutter dia. TD worked as soon as I loaded 3.17.2 However adding the MyGCode.js didn't get DATE_TIME to work. So I changed the include statment at the top of Emc2.js to read 'include("MyGCode.js")' and it still is not working.


I would not recommend to directly change the configurations that come with QCAD/CAM (otherwise you might have to start over after every update).

Instead, you should always create your own configuration and derive it from an existing configuration. Typically, you would derive from the configuration that is closest to what you need (in your case, that seems to be Emc2.js). This way you are re-using everything in the base configuration (Emc2.js) but overriding some of the settings in your own configuration (MyGCode.js):

Code: Select all

include("Emc2.js");

function MyGCode(cadDocumentInterface, camDocumentInterface) {
    Emc2.call(this, cadDocumentInterface, camDocumentInterface);

    this.decimals = 4;
    this.unit = RS.Millimeter;

    // register variable for date and time:
    this.dateTime = undefined;
    this.registerVariable("dateTime", "DATE_TIME", true, "",  0);

    this.header = [
        "( date/time: [DATE_TIME] )",
        "( tool dimater: [TD] )"
    ];
}

MyGCode.prototype = new Emc2();

MyGCode.displayName = "MyGCode";

MyGCode.prototype.writeFile = function(fileName) {
    // init date / time variable:
    var today = new Date();
    this.dateTime = formatDate(today, "dd/MMM/yyyy hh:mm:ss");

    Emc2.prototype.writeFile.call(this, fileName);
};

jamby
Active Member
Posts: 25
Joined: Fri Jun 24, 2016 2:41 pm

Re: additions to the header

Postby jamby » Mon Jul 03, 2017 4:23 pm

Andrew

Then the correct usage of the "MyGCode.js" is to put a copy in the "postprocessor" subdirectory. And make no changes to any other files. Is that correct?

Sorry for my ignorance

Jim

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

Re: additions to the header

Postby andrew » Mon Jul 03, 2017 4:36 pm

jamby wrote:Then the correct usage of the "MyGCode.js" is to put a copy in the "postprocessor" subdirectory. And make no changes to any other files. Is that correct?


Yes.

You might want to also rename MyGCode to something meaningful in both the file name and inside the file (class name).

jamby
Active Member
Posts: 25
Joined: Fri Jun 24, 2016 2:41 pm

Re: additions to the header

Postby jamby » Tue Jul 25, 2017 7:34 pm

Andrew

I got most of the header working as I wanted but the "date/time" still eludes me.
Attached is a copy of the post-processor I edited.

Thanks
Jim

Yeah, I know its a kid with a new toy.

LxcncIn.txt
(1.99 KiB) Downloaded 42 times


Return to “QCAD/CAM”

Who is online

Users browsing this forum: No registered users and 3 guests