local inst = mc.mcGetInstance() local ZGageBlockHeight = 3.3091 function m1000() ------ Auto Depth Setting ------ SetDepth() end function SetDepth() ------ Auto Depth Setting ------ mc.mcCntlGcodeExecuteWait(inst, "G00 G53 X35.93 Y2.75\n") -- go to point over depth setter mc.mcCntlSetLastError(inst, 'Setting Tool Height') mc.mcCntlGcodeExecuteWait(inst, "G91 G31 Z-4 F50") --probe the new tool mc.mcCntlGcodeExecuteWait(inst, "G91 G0 Z+0.1") --Retract from the probe mc.mcCntlGcodeExecuteWait(inst, "G91 G31 Z-0.15 F5") --Probes at slow speed local measure_1 = mc.mcAxisGetPos(inst,2) --Saves probed Z position mc.mcCntlGcodeExecuteWait(inst, "G91 G0 Z+0.1") --Retracts from the probe mc.mcCntlGcodeExecuteWait(inst, "G91 G31 Z-0.15 F5") --Probes at slow speed local measure_2 = mc.mcAxisGetPos(inst,2) --Saves probed Z position local measured_average = (measure_1 + measure_2)/2 --Averages two probed values local offSet = measure_2 - measured_average local adjustedHeight = ZGageBlockHeight + offSet mc.mcAxisSetPos(inst,2,adjustedHeight) --Sets current Z postion to gage block height with measured offset GCode = "" GCode = GCode .. "G00 G90 G53 Z0\n" --Retract GCode = GCode .. "G00 G53 X33 Y2.75\n" -- Move to clear spot mc.mcCntlGcodeExecuteWait(inst, GCode) end if(mc.mcInEditor() == 1) then -- If you are in the mcLua editor, this will cause your script to execute if you Run or Debug -- Make sure your Capitalization and numbers match that of the function you are calling m1000() end