function m6() local inst = mc.mcGetInstance() local selectedTool = mc.mcToolGetSelected(inst) local currentTool = mc.mcToolGetCurrent(inst) local lowerinput = mc.ISIG_INPUT4 local Upperinput = mc.ISIG_INPUT8 local ReleaseTool = mc.OSIG_OUTPUT0 local Raisetool = mc.OSIG_OUTPUT4 local OpenDoor = mc.OSIG_OUTPUT3 -- works tool door local OpenDoornow = mc.mcSignalGetHandle(inst, OpenDoor) local Toolup = mc.mcSignalGetHandle(inst, Raisetool) local ToolRelease = mc.mcSignalGetHandle(inst, ReleaseTool) local xstart = mc.mcAxisGetPos(inst,0) local ystart = mc.mcAxisGetPos(inst,1) if selectedTool == currentTool then mc.mcCntlSetLastError(inst, "Current tool == Selected tool So there is nothing to do") else mc.mcCntlGcodeExecuteWait(inst, "G00 G53 Z0\nG00 G53 X-.072 Y-.030");--Move the Z axis all the way up mc.mcSignalSetState(OpenDoornow, 1) mc.mcSignalWait(inst,mc.ISIG_INPUT7 ,1,0) mc.mcCntlGcodeExecuteWait(inst, "G00 G53 Z-3.04");--Move the Z axis all the way up ------ Release drawbar ------ --mc.mcSignalSetState(Toolup, 0) if currentTool == 0 then else mc.mcCntlGcodeExecuteWait(inst, "G0 A"..currentTool-1 ) mc.mcSignalSetState(Toolup, 1) mc.mcSignalWait(inst,mc.ISIG_INPUT12 ,1,0) --mc.mcSignalSetState(Toolup, 0) mc.mcSignalSetState(ToolRelease, 1) wait(1) mc.mcSignalSetState(Toolup, 0) mc.mcSignalWait(inst,mc.ISIG_INPUT10,1,0) -- mc.mcSignalSetState(ToolRelease, 0) --wait(.7) end mc.mcCntlGcodeExecuteWait(inst, "G0 A"..selectedTool-1 ) mc.mcSignalSetState(Toolup, 1) mc.mcSignalSetState(ToolRelease, 1) mc.mcSignalWait(inst,mc.ISIG_INPUT12 ,1,0) --mc.mcSignalSetState(Toolup, 0) wait(.3) mc.mcSignalSetState(ToolRelease, 0) wait(.71) mc.mcSignalSetState(Toolup, 0) mc.mcSignalWait(inst,mc.ISIG_INPUT10,1,0) mc.mcSignalSetState(OpenDoornow, 0) mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. " Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start mc.mcToolSetCurrent(inst, selectedTool) --wait(.53) -- mc.mcCntlGcodeExecuteWait(inst, "G0 G53 Z0" ) -- mc.mcCntlGcodeExecuteWait(inst, "G0 G53 X0 Y0" ) mc.mcCntlGcodeExecuteWait(inst, "G90 G53 Z0") mc.mcCntlGcodeExecuteWait(inst, "G90 G0 G54 X"..xstart.."Y"..ystart ) end end function wait(seconds) local start = os.time() repeat until os.time() > start + seconds end if (mc.mcInEditor() == 1) then m6() end