[Solved]dxf file name in gcode

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
jamby
Full Member
Posts: 55
Joined: Fri Jun 24, 2016 2:41 pm

[Solved]dxf file name in gcode

Post by jamby » Wed Nov 06, 2019 3:23 am

Hi

I use a number of headers in my gcode

this.header = [
"%",
"( CREATED WITH QCAD-CAM )",
"( FILE PATH: [FILEPATH])",
"( FILE NAME: [FILENAME])",
"( DATE/TIME: [DATE_TIME])",
"( CUTTER NUM: [T])",
"( CUTTER DIA: [TD])",
"( CUTTER NOTES: [PROGRAM_NAME])",
"[N] G20 G17 G40 G49 G80 G90 G94",
"[N] G64 P0.001" // tighten tolerance
];

Is there one that will write the filepath and filename for the dxf file that is generating the gcode?

Thanks
Jim
Last edited by jamby on Thu Nov 07, 2019 5:56 pm, edited 1 time in total.

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

Re: dxf file name in gcode

Post by andrew » Wed Nov 06, 2019 9:05 am

No, I will add those to the next release of GCodeBase.

For now, you can register your own variables:

In the constructor:

Code: Select all

    // register additional variables:
    this.registerVariable("inputFileName",       "INFILENAME",           true,  "",  0);
    this.registerVariable("inputFilePath",       "INFILEPATH",           true,  "",  0);
Add a function writeFile:

Code: Select all

MyPostPRocessor.prototype.writeFile = function(fileName) {
    // initialize additional variables:
    this.inputFilePath = this.cadDocument.getFileName();
    this.inputFileName = new QFileInfo(this.inputFilePath).fileName();

    return GCodeBase.prototype.writeFile.call(this, fileName);
};
This gives you [INFILENAME] and [INFILEPATH].

jamby
Full Member
Posts: 55
Joined: Fri Jun 24, 2016 2:41 pm

Re: dxf file name in gcode

Post by jamby » Thu Nov 07, 2019 4:08 am

Sorry Andrew

But as always I am having trouble getting this to work.
LxcncIn.js
(2.64 KiB) Downloaded 502 times
GCodeBase.js
(7.6 KiB) Downloaded 482 times
Maybe you could take a look?

Thanks
Jim

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

Re: dxf file name in gcode

Post by andrew » Thu Nov 07, 2019 8:52 am

You have two implementations of LxcncIn.prototype.writeFile. The second one will overwrite the first one:

Code: Select all

// define writeFile:
LxcncIn.prototype.writeFile = function(fileName) { ... };

// define writeFile again, with different contents,  overwriting the first one:
LxcncIn.prototype.writeFile = function(fileName) { ... };
You'll have to combine the contents to get only one writeFile:

Code: Select all

LxcncIn.prototype.writeFile = function(fileName) {
    // init date / time variable:
    var today = new Date();
    this.dateTime = formatDate(today, "dd/MMM/yyyy hh:mm:ss");
    
    // initialize additional variables:
    this.inputFilePath = this.cadDocument.getFileName();
    this.inputFileName = new QFileInfo(this.inputFilePath).fileName();
        
    GCodeIN.prototype.writeFile.call(this, fileName);
};

jamby
Full Member
Posts: 55
Joined: Fri Jun 24, 2016 2:41 pm

Re: dxf file name in gcode

Post by jamby » Thu Nov 07, 2019 3:59 pm

Andrew

I still have a error somewhere?

Version: 3.18.1.0 (3.18.1)
Internet: QCAD.org
Build Date: Oct 4 2017
Revision: 24e23aa
Qt Version: 5.8.0
Architecture: x86_64
Compiler: gcc 4.8.1

PostP-test.ngc
(417 Bytes) Downloaded 483 times
LxcncIn.js
(2.52 KiB) Downloaded 493 times
Thanks
Jim

jamby
Full Member
Posts: 55
Joined: Fri Jun 24, 2016 2:41 pm

Re: dxf file name in gcode

Post by jamby » Thu Nov 07, 2019 5:56 pm

Andrew

And the error is the operator. If you don't save the file with a name before compiling the gcode you won't get a name in the INFILENAME value.

Its working fine now....

Thanks again
Jim

Post Reply

Return to “QCAD/CAM”