-- (I like this layout and setup_10/28/22 ) -- 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 valX, rc = mc.mcAxisGetMachinePos (inst, mc.X_AXIS) --- Get the position of the X axis in Machine Position-- local valY, rc = mc.mcAxisGetMachinePos (inst, mc.Y_AXIS) --- Get the position of the Y axis in Machine Position-- local valZ, rc = mc.mcAxisGetMachinePos (inst, mc.Z_AXIS) --- Get the position of the Z axis in Machine Position-- -------------------------------------------------------------------------------------------------------------------------------------------------------------------- if selectedTool == currentTool then mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do") else mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 Z-0.125 M05" .. "\n G90 G53 X1.1363 Y-13.6805" ) --Tool Change Position -- mc.mcCntlSetLastError(inst, "Change to tool " .. tostring(selectedTool) .. " and press start to touch off") --Message at beginning of tool change-- 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, "Moving to Tool Change Position") mc.mcCntlGcodeExecuteWait(inst, string.format("G0 G53 Z0" .. "\n G0 G53 X%0.4f Y%0.4f", tostring(xtpos), tostring(ytpos)))--tool change position-- wx.wxMessageBox("Change to the next tool".."\n Click OK".."\n Then Cycle Start to Continue."). -- PROBING -- mc.mcCntlSetLastError(inst, "Performing touch routine") 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") mc.mcCntlGcodeExecuteWait(inst, string.format("G90"))--Back to ABS-- mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. " Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start-- -- Check for Probe Contact -- local didStrike = mc.mcCntlProbeGetStrikeStatus(inst) if (didStrike == 1) then --#5063 = User position #5073 = Machine position-- --local value = mc.mcCntlGetPoundVar(inst, 5063)-- local value = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_POS_Z) -- Same as line above but line above uses the Mach constant instead of the #var -- mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, selectedTool, value) -- Set the tool height to what was determined by probe move -- mc.mcCntlGcodeExecute(inst, string.format ("G43 H" .. tostring(selectedTool))) mc.mcCntlSetLastError(inst, string.format("Tool " .. tostring(selectedTool) .. " H offset set to %0.4f", value)) mc.mcCntlGcodeExecuteWait(inst, "G90 G53 M03") -- Spindle Start -- wx.wxMessageBox ("Probing Complete" .. "\n TLO Set".."\n Select OK to Continue") else mc.mcCntlSetLastError(inst, "The touch move did not touch so we did not set a tool offset.") --Message that shows after Cycle Start-- end local MyChoice = wx.wxMessageBox("Tool Change Complete".."\n Click OK to continue",16) --- brings up a dialog box and waits for a selection to proceed --- if (MyChoice == 16) then ---16 is cancel --- rc = mc.mcCntlSetLastError(inst, '!! Probing Cancelled !!') return --- Move to Return position --- elseif (MyChoice == 4) then --- 4 is OK selected --- mc.mcCntlGcodeExecute(inst, string.format('G' .. posmode))---return to pre macro mode G90, or G91 --- mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 Z-0.25") ---Move Z to safe height location --- mc.mcCntlGcodeExecute(inst, "G90 G53 G0 X" .. tonumber(valX) .. "Y" .. tonumber(valY)) ---Move back to X & Y initial location --- mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z" .. tonumber(valZ)) ---Move back to Z initial location --- mc.mcCntlSetLastError(inst, "Tool Change Complete H ".. tostring(selectedTool) .. " set to ".. tostring(ToolLength).." inches") end end wx.wxMessageBox ("Toolchange Complete" .. "\n TLO Set" ) end if (mc.mcInEditor() == 1) then m6() end