Page 1 of 1

[Solved]dxf file name in gcode

Posted: Wed Nov 06, 2019 3:23 am
by jamby
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

Re: dxf file name in gcode

Posted: Wed Nov 06, 2019 9:05 am
by andrew
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].

Re: dxf file name in gcode

Posted: Thu Nov 07, 2019 4:08 am
by jamby
Sorry Andrew

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

Thanks
Jim

Re: dxf file name in gcode

Posted: Thu Nov 07, 2019 8:52 am
by andrew
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);
};

Re: dxf file name in gcode

Posted: Thu Nov 07, 2019 3:59 pm
by jamby
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 491 times
LxcncIn.js
(2.52 KiB) Downloaded 500 times
Thanks
Jim

Re: dxf file name in gcode

Posted: Thu Nov 07, 2019 5:56 pm
by jamby
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