/* v.11 This is my LinuxCNC Gcode config file for the Qcad Cam add-on, can I remind you that the QCad add-on's are not "free" but only a trial. You can purchase a full version licence from Andrew Mustun at qcad.org . Z safety and Z clear are set in the CAM Dialog and and asigned to variables #19 and #18. Other parameters are set in the layer names as in the following:- 'Z(float)' Sets the Z value for this layer. Example layer name- servo_cutsZ-5.4 '#(int)' The Z value for this layer is linked to this variable. Different layers may use the same Z variable. Example layer name -servo_cuts#14 'Z(float)' with '#(int)' This assigns a Z value to the # Variable set in the same layer. Each variable used must be assigned a Z value in one of the layers. Example main_cuts#14Z-3.4 'F(int)' Set or change feed rate. Example servo_cuts#14F800 'R' all rapid moves. None of the above settings are needed. Example Rapid_guides 'L' after a rapid will send the tool at a angle to Level '# ' which also must be set. Example layer name Leadin#15 'G41' 'G42' 'G40' Set tool diameter compensation. This will be set back to G40 at the next rapid move. Edit a line in GCodesrl.prototype.writeHeader = function() or the opening Gcode line ("G10 L1 P1 R5") to suit your tool diameter. Example servo_cuts#14G42 'End' this ends the resulting file, with a M30 of course, this is used with one long contour with rapids. All entites after this will be ignored. This file is added to the CamConfigurations directory as 'GCodesrl.js' along side a unchanged GCode.js. More features may be added later. Use, test and adjust to suit your needs. For more information or updates in the future go to srlfoamies.com and follow a blog link. Still to add- -Error stuff.(maybe one day) -Custom properties to have priority over layer names */ include("GCode.js"); function GCodesrl(documentInterface, newDocumentInterface) { GCode.call(this, documentInterface, newDocumentInterface); this.os = 40; this.endc = 1; // this.globalOptions = "GCode"; this.layerOptions = undefined; } GCodesrl.prototype = new GCode(); GCodesrl.prototype.initGlobalOptionWidget = function(w) { switch (w.objectName) { case "ZSafety": w.addItems(["100", "75", "19", "50"]); w.setEditText("100"); break; case "ZClear": w.addItems(["10", "20", "30"]); w.setEditText("20"); break; case "ZCutting": w.addItems(["2.6", "6", "10"]); w.setEditText("2.6"); break; } }; GCodesrl.prototype.getFileExtensions = function() { return ["ngc"]; }; GCodesrl.prototype.getLineNumberCode = function() { var ret = sprintf("N%d", this.lineNumber); this.lineNumber += 10; return ret; }; GCodesrl.prototype.getZCode = function(value) { var v = value; if (this.getIncrementalXYZ()) { v -= this.zPrev; } if (v > 4900) { return sprintf("Z%.3f", v - 5000); } else { return sprintf("Z#%.3f", v); } }; GCodesrl.prototype.getSafetyZLevel = function() { return parseFloat(this.document.getVariable("Cam/ZSafety", 100.0)); //return 19; hack line }; GCodesrl.prototype.getToolUpLevel = function() { return parseFloat(this.document.getVariable("Cam/ZClear", 2.0)); //return 18; hack line }; GCodesrl.prototype.getToolDownLevel = function() { // document wide default value: var docValue = 20; var entity = this.getEntity(); if (isNull(entity)) { return docValue; } // layer specific value: var layerId = entity.getLayerId(); var layer = this.document.queryLayer(layerId); if (isNull(layer)) { return docValue; } //error checking to be done here var lt = layer.getName(); var vf = lt.indexOf("F"); if (vf != -1) this.f = parseInt(lt.slice(vf+1)); var idx = lt.indexOf("#"); if (idx!= -1){ return parseInt(lt.slice(idx+1)); } else { var idz = lt.indexOf("Z"); if (idz!= -1){ var nn = parseFloat(lt.slice(idz+1)); return nn + 5000; } } return docValue; }; GCodesrl.prototype.writeToolUp = function() { this.g = GCode.Mode.Rapid; this.z = 18; this.toolPosition = GCode.ToolPosition.Up; if (this.feedRateSet!==true) { this.writeLine(undefined, "F500"); this.feedRateSet=true; } else { this.writeLine(); } this.toolIsUp(); }; GCodesrl.prototype.writeBeforeRapidLinearMove = function(x, y) { if (this.sinlayname("G41") != -1){ if (this.os == 41) return; this.writeLine("G41"); this.os = 41; return; } if (this.sinlayname("G42") != -1){ if (this.os == 42) return; this.writeLine("G42"); this.os = 42; return; } else{ if (this.os == 40) return; } this.writeLine("G40"); this.os = 40; }; GCodesrl.prototype.writeAfterRapidLinearMove = function(x, y) { }; GCodesrl.prototype.prepareForCutting = function() { // force tool down before normal move: if (this.toolPosition !== GCode.ToolPosition.Down) { // force tool up before tool down: if (this.toolPosition !== GCode.ToolPosition.Up) { this.writeToolUp(); //on rapid and down } if (this.sinlayname("L")!=-1) { this.z = this.getToolDownLevel(); return; } } this.writeToolDown(); }; GCodesrl.prototype.sinlayname = function( s) { var entity = this.getEntity(); var layerId = entity.getLayerId(); var layer = this.document.queryLayer(layerId); var lt = layer.getName(); return (lt.indexOf(s)); }; // G01: GCodesrl.prototype.writeLinearMove = function(x, y) { if (this.sinlayname("R")!=-1){ this.writeRapidLinearMove(x, y); return; } if (this.sinlayname("End")!=-1){ this.writeFooter(); this.endc = 0; } GCode.prototype.writeLinearMove.call(this, x, y); }; GCodesrl.prototype.writeHeader = function() { this.writeLine("G10 L1 P1 R5"); var layers = this.document.queryAllLayers(); for (var l = 0; l < layers.length; ++l) { var layer = this.document.queryLayer(layers[l]); var lt = layer.getName(); var vz = lt.indexOf("#"); var nz = lt.indexOf("Z"); if (vz != -1 && nz != -1 && !layer.isFrozen()) { var vzs = parseInt(lt.slice(vz+1)); var nzs = parseFloat(lt.slice(nz+1)); this.writeLine("#" + vzs + " = " + nzs + " (layer " + lt + ")"); } } var cutz = parseFloat(this.document.getVariable("Cam/ZCutting", -1.0)); var safy = this.getSafetyZLevel(); var cler = this.getToolUpLevel(); this.writeLine("#20 = " + cutz + " (cut z manual write)"); this.writeLine("#19 = " + safy + " (safty manual write)"); this.writeLine("#18 = " + cler + " (clear manual write)"); this.writeLine("S20000 M3"); this.writeRapidZMove(19); this.toolPosition = GCode.ToolPosition.Clear; }; GCodesrl.prototype.writeFooter = function() { this.writeToolUp(); this.writeRapidZMove(19); this.toolPosition = GCode.ToolPosition.Clear; this.writeLine("M30"); }; GCodesrl.prototype.writeLine = function(custom, append) { if (this.endc != 1) return; GCode.prototype.writeLine.call(this, custom, append); };