function m6() local inst = mc.mcGetInstance() --Get the instance of Mach4 local currentTool = mc.mcToolGetCurrent(inst) local selectedTool = mc.mcToolGetSelected(inst) local tpos = ((selectedTool * 60) - 2) if (selectedTool ~= currentTool) then --Change tool mc.mcCntlGcodeExecuteWait(inst, "G28.1 A0\nG53 G1 F75.0 A%4.4f\nG53 A-2.0000", (tpos + 12)) --Reference, move to position, back up to lock position local hReg, rc = mc.mcRegGetHandle(inst, "iRegs0/CurrentSlot") rc = mc.mcRegSetValue(hReg, selectedTool) mc.mcToolSetCurrent(inst, selectedTool) end end --This function is here to allow the debugging from the Lua editor if (mc.mcInEditor() == 1) then m6() end