I have not tried this but I would think this is all the code you need.
-- Mach4Turn 8 positon tool Turret
function m6()
inst = mc.mcGetInstance()
selectedtool = mc.mcToolGetSelected(inst)
currenttool = mc.mcToolGetCurrent(inst)
Ulock = 10 --' Sets the Unlock Movement in Degrees Value
Rlock = 10 -- ' Sets the Relock Movement in Degrees Value
T1SafePosX = 2.25
T1SafePosZ = 1.5
if (selectedtool >
or (selectedtool < 1) then
mc.mcCntlSetLastError(inst,"Program Stopped due to Tool Number Out of Range")
do return end
end
if (selectedtool == currenttool) then
mc.mcCntlSetLastError(inst,"Tool is the same NO tool change needed")
do return end
end
--'------------------- Move to Safe Tool Position -----------
mc.mcCntlSetLastError(inst," Move to Tool Safe Pos")
mc.mcCntlGcodeExecuteWait(inst, "G1 F30 X" .. T1SafePosX);
mc.mcCntlGcodeExecuteWait(inst, "G1 F40 Z" .. T1SafePosZ);
mc.mcCntlSetLastError(inst,"Safe XZ Move Completed")
--'------ Begin Tool Change , UNLOCK turret --------------
mc.mcCntlSetLastError(inst," Tool Turret UNLOCKING ")
mc.mcCntlGcodeExecuteWait(inst, " G91"); --'Set to INC
mc.mcCntlGcodeExecuteWait(inst, " G92 C0");
--'------ Select Tool ------------------------------------
mc.mcCntlSetLastError(inst,"Moving to Tool# " ..selectedtool )
if (selectedtool > currenttool) then
Moves = selectedtool - currenttool
else
Moves = ((8 - currenttool) + selectedtool)
end
mc.mcCntlSetLastError(" G00 C " ..Moves);
Moves = (Moves * 45) + Ulock
mc.mcCntlGcodeExecuteWait(inst, " G00 C" ..Moves);
mc.mcCntlSetLastError(inst,"Tool#1 Loaded")
mc.mcCntlSetLastError(inst," Tool Turret LOCKING ")
mc.mcCntlGcodeExecuteWait(inst, " G92 C0");
mc.mcCntlGcodeExecuteWait(inst, " G00 C-" ..Rlock ); -- ' Lock Turret
mc.mcCntlGcodeExecuteWait(inst, "G92 C0");
mc.mcCntlGcodeExecuteWait(inst, "G90"); --' Reset to ABS
tool = selectedtool
mc.mcToolSetCurrent(inst, selectedtool)
if (mc.mcInEditor() == 1) then
m6()
end
end