You really wan't to be careful here, as long as work tops are the same, its all fine, but if not you'll crash.
I did something like this in my post to allow whether or not I wanted a z0
Add SafePlaneRetract to properties
properties = {
writeMachine: true, // write machine
writeTools: true, // writes the tools
preloadTool: true, // preloads next tool on tool change if any
showSequenceNumbers: false, // show sequence numbers
sequenceNumberStart: 10, // first sequence number
sequenceNumberIncrement: 5, // increment for sequence numbers
sequenceNumberOnlyOnToolChange: false, // only output sequence numbers on tool change
optionalStop: true, // optional stop
separateWordsWithSpace: true, // specifies that the words should be separated with a white space
useRadius: false, // specifies that arcs should be output using the radius (R word) instead of the I, J, and K words.
useParametricFeed: false, // specifies that feed should be output using Q values
showNotes: false, // specifies that operation notes should be output
useG0: false, // allow G0 when moving along more than one axis
useG28: false, // specifies that G28 should be used instead of G53
useSubroutines: false, // specifies that subroutines should be generated
useG187: false, // use G187 to set smoothing on the machine
homePositionCenter: true, // moves the part in X in center of the door at end of program (ONLY WORKS IF THE TABLE IS MOVING)
optionallyMeasureTools: false, // cycle through each tool used at the beginning of the program when block delete is turned off - this allows the operator to easily measure all tools before they are used for the first run of the program
BetweenZ: 1.0,
WorkOffsetCount: 0,
SafePlaneRetract: false,
Finish_G53_X_Pos: -15,
StopAtOffset: 9,
StopAfterSection: -1,
//WorkOffsetBase: 0,
MinimumG187: 0.010,
G187Ratio: 2,
G187ResetVal: 0.0004,
G1RapidG187: 0.100,
BeepOnDone: true,
SpiralArcSections: 16,
LoadStartToolOnEnd: true,
TimeStartEnd: true,
PartsCounter: 1
};
function onSection() {
var forceToolAndRetract = optionalSection && !currentSection.isOptional();
var IsRigidTapping = false;
var IsProbing = false;
optionalSection = currentSection.isOptional();
var insertToolCall = isFirstSection() ||
currentSection.getForceToolChange && currentSection.getForceToolChange() ||
(tool.number != getPreviousSection().getTool().number);
var retracted = false; // specifies that the tool has been retracted to the safe plane
var newWorkOffset = isFirstSection() ||
(getPreviousSection().workOffset != currentSection.workOffset); // work offset changes
var newWorkPlane = isFirstSection() ||
!isSameDirection(getPreviousSection().getGlobalFinalToolAxis(), currentSection.getGlobalInitialToolAxis());
if (insertToolCall || newWorkOffset || newWorkPlane) {
// stop spindle before retract during tool change
if (insertToolCall && !isFirstSection()) {
//onCommand(COMMAND_STOP_SPINDLE);
}
// retract to safe plane
retracted = true;
if (!properties.SafePlaneRetract) {
} else if (properties.useG28) {
writeBlock(gFormat.format(28), gAbsIncModal.format(91), "Z" + xyzFormat.format(0));
} else {
if (newWorkOffset || newWorkPlane) {
gMotionModal.reset();
writeBlock(gAbsIncModal.format(90), gFormat.format(53), gMotionModal.format(0), "Z" + xyzFormat.format(0),"(Safe Z)");
}
}
writeBlock(gAbsIncModal.format(90));
zOutput.reset();