I have a question If I may I know this topic is a few versions back. The format that we use for the G116 macro is G116 PT=1 PQ=2 (PT is current tool PQ is preload)
we have them all on the same line so that the variables are passed through to the macro.
I wrote the below code for the stock post and it works well as long as we don't try to use the same tool in multiple toolpaths. Once we try to use it in multiple toolpaths it gives an error that the nextTool is undefined. This adds a check box incase someone doesn't want to use either the HA/DA or the G116 and will just do the default as well. Am i trying to make this overcomplicated or am I just missing why it thinks on repeat tool numbers it doesn't think the previous variable is undefined.
Thanks in advance
//user-defined properties
useG116: {
title : "Enable G116 instead of M6",
description: "Use G116 Macro instead of M6 for tool change",
group : "preferences",
type : "boolean",
value : false,
scope : "post"
},
useHADA: {
title : "Enable HA DA instead of Hxx Dxx",
description: "Use HA and DA For Tool Len and Dia Offset",
group : "preferences",
type : "boolean",
value : false,
scope : "post"
}
// within the onSection function
if (getProperty("preloadTool")) {
if ((!isLastSection()) && (getProperty("useG116"))) {
forceSequenceNumbers(true);
writeBlock("G0 G90 G30 P1", "(THIS IS THE RESTART LINE error out)");
forceSequenceNumbers(false);
var tNextTool = getNextTool(tool.number);
var firstToolNumber = getSection(0).getTool().number
if (tNextTool == firstToolNumber){
writeBlock(gFormat.format(116), "PT=" + toolFormat.format(tool.number), "PQ=" + toolFormat.format(firstToolNumber));
} else {
writeBlock(gFormat.format(116), "PT=" + toolFormat.format(tool.number), "PQ=" + toolFormat.format(tNextTool.number));
}
}
else
if (getProperty('useG116')){
forceUseG116(true);
} else
if (getProperty("safeToolChange")) {
forceSequenceNumbers(true);
writeBlock("G0 G90 G30 P1", "(THIS IS THE RESTART LINE Hi How are you )");
writeBlock("IF [ VTLCN EQ " + toolFormat.format(tool.number) + " ] " + skipNLines(5));
writeBlock("IF [ VTLNN EQ " + toolFormat.format(tool.number) + " ] " + skipNLines(3));
writeBlock("IF [ VTLNN EQ 0 ] " + skipNLines(2));
writeBlock(mFormat.format(64));
writeBlock(mFormat.format(6),"T" + toolFormat.format(tool.number));
} else {
if (getProperty("useG116")) {
if (!isFirstSection()){
var firstToolNumber = getSection(0).getTool().number;
forceSequenceNumbers(true);
writeBlock("G0 G90 G30 P1", "(THIS IS THE RESTART LINE)");
forceSequenceNumbers(false);
var nextTool = getNextTool(tool.number);
writeBlock(gFormat.format(116), "PT=" + toolFormat.format(tool.number), "PQ=" + toolFormat.format(firstToolNumber));
}
}
else
if (!isFirstSection()) {
writeToolBlock(formatComment("T" + toolFormat.format(tool.number)));
writeBlock(mFormat.format(6));
} else {
writeToolBlock("T" + toolFormat.format(tool.number), mFormat.format(6));
}
}
var nextTool = getNextTool(tool.number);
if (nextTool) {
if (getProperty("useG116")){
writeBlock(formatComment("*"));
} else
writeBlock("T" + toolFormat.format(nextTool.number));
} else {
// preload first tool
var firstToolNumber = getSection(0).getTool().number;
if (getProperty("useG116")) {
if (tool.number != firstToolNumber) {
writeBlock(gFormat.format(116), "PT=" + toolFormat.format(tool.number), "PQ=" + toolFormat.format(firstToolNumber));
} else
writeBlock(formatComment("*"));
}
else
if (tool.number != firstToolNumber) {
writeBlock("T" + toolFormat.format(firstToolNumber));
} else if (getProperty("safeToolChange")) {
writeBlock(formatComment("*"));
}
}
} else {
if (getProperty("safeToolChange")) {
forceSequenceNumbers(true);
writeBlock("IF [ VTLCN EQ " + toolFormat.format(tool.number) + " ] " + skipNLines(2));
writeBlock(mFormat.format(6), "T" + toolFormat.format(tool.number));
writeBlock(formatComment("*"));
} else {
writeToolBlock("T" + toolFormat.format(tool.number), mFormat.format(6));
}
}
forceSequenceNumbers(false);
}