function m6() local inst = mc.mcGetInstance(); local selectedTool = mc.mcToolGetSelected(inst) local currentTool = mc.mcToolGetCurrent(inst) local maxDown = -2.0000 --Max distance Z will go down in the touch routine-- local rate = 5 --Feed rate the Z will go down in the touch routine-- local safeZ = 1.5 --Coordinates the Z will rapid to after touch move-- local xtpos = 19.9291 --edit this for x tool probe posititon-- local ytpos = -13.8355 --edit this for y tool probe posititon-- local posmode = mc.mcCntlGetPoundVar(inst, mc.SV_MOD_GROUP_3) -- gets the current mode so we can return to it when macro ends ------- if selectedTool == currentTool then mc.mcCntlSetLastError(inst, "Current tool == Continuing!!") else mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 Z-0.125 M05" .. "\n G90 G53 X1.1363 Y-13.6805" ) --Move to tool Change Position -- wx.wxMessageBox("Tool Change position Aquired?".. "\n IF SO - Change tool, select OK & then Cycle Start.") mc.mcCntlSetLastError(inst, "Change to tool " .. tostring(selectedTool) .. " and press start to touch off") mc.mcCntlToolChangeManual(inst, true) --This will pause the tool change here and wait for a press of cycle start to continue-- mc.mcToolSetCurrent(inst, selectedTool) mc.mcCntlSetLastError(inst, "Tool Change Position - Please change Tool.") mc.mcCntlGcodeExecuteWait(inst, string.format("G0 G53 Z0" .. "\n G0 G53 X%0.4f Y%0.4f", tostring(xtpos), tostring(ytpos)))--Move to tool probing position-- wx.wxMessageBox("Check tool".. "\n Then select OK to Continue.") mc.mcCntlSetLastError(inst, "Performing touch routine") -- Probing -- mc.mcCntlGcodeExecuteWait(inst, string.format("G91 G31 Z%0.4f F%0.4f\nG0 Z%0.4f", tostring(maxDown), tostring(rate), tostring(safeZ))) --Probe move-- mc.mcCntlSetLastError(inst, "Touch move complete") ------ Check for Probe strike (may need to replace or remove!)------ local didStrike = mc.mcCntlProbeGetStrikeStatus(inst) if (didStrike == 1) then local value = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_POS_Z) mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, selectedTool, value) mc.mcCntlGcodeExecute(inst, string.format("G01 G43 H" .. tostring(selectedTool))) wx.wxMessageBox ("Toolchange Complete" .. "\n TLO Set" ) mc.mcCntlSetLastError(inst, string.format("Tool " .. tostring(selectedTool) .. " H offset set to %0.4f", value)) else wx.wxMessageBox ("Toolchange DID NOT Complete!!" .. "\n NO TLO Set" ) mc.mcCntlSetLastError(inst, "The probe move did not touch" .. "No Tool Offset Recorded.") --Message that shows after Cycle Start-- end -- mc.mcCntlGcodeExecuteWait(inst, string.format("G90"))--Back to ABS ---- mc.mcCntlGcodeExecute(inst, string.format('G' .. posmode))--return to pre macro mode G90, or G91-- -- m6 doesn't change spindle rpm or finish macro when running gcode, but does when debugging & in MDI ???? -- mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. " Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start-- end end if (mc.mcInEditor() == 1) then m6() end