I am far from a Lua expert but here is my custom cycle start.
You might be able to find what you need it it.
---------------------------------------------------------------
-- Cycle Start() function.
---------------------------------------------------------------
function CycleStart()
local rc;
local tab, rc = scr.GetProperty("MainTabs", "Current Tab")
local tabG_Mdione, rc = scr.GetProperty("nbGCodeMDI1", "Current Tab")
local tabG_Mditwo, rc = scr.GetProperty("nbGCodeMDI2", "Current Tab")
------------------------------------------------------------------------------------
--if machine home not done exit run with message
MachHmdRegH = mc.mcRegGetHandle(inst, 'iRegs0/MachHmd')
MachHmd = mc.mcRegGetValue(MachHmdRegH)
ATCOnRegH = mc.mcRegGetHandle(inst, 'iRegs0/ATCOnOff')
ATCOn = mc.mcRegGetValue(ATCOnRegH)
if (MachHmd == 0) and (ATCOn == 1)then
wx.wxMessageBox('Please Set Machine Home Before Clicking Run')
else
------------------------------------------------------------------------------------
--See if we have to do an MDI command and if so, which one
if ((tonumber(tab) == 0 and tonumber(tabG_Mdione) == 1) or (tonumber(tab) == 2 and tonumber(tabG_Mditwo) == 1 )) then
local state = mc.mcCntlGetState(inst);
if (state == mc.MC_STATE_MRUN_MACROH) then
mc.mcCntlCycleStart(inst);
--mc.mcCntlSetLastError(inst, "Do Cycle Start");
else
if (tonumber(tab) == 0) then
scr.ExecMdi('mdi1');
--mc.mcCntlSetLastError(inst, "Do MDI 1");
else
scr.ExecMdi('mdi2');
--mc.mcCntlSetLastError(inst, "Do MDI 2");
end
end
elseif tonumber(tab) > 2 then --No G Code or MDI panel is displayed so Do Nothing
--mc.mcCntlSetLastError(inst, "Nothing to Start");
else --Do CycleStart
--mc.mcCntlSetLastError(inst, "Do Cycle Start");
--if project home or surface not set exit run with message
hregHm1 = mc.mcRegGetHandle(inst, 'iRegs0/ProjHm1Set')
ProjHmd1 = mc.mcRegGetValue(hregHm1)
hregHm2 = mc.mcRegGetHandle(inst, 'iRegs0/ProjHm2Set')
ProjHmd2 = mc.mcRegGetValue(hregHm2)
hreg2 = mc.mcRegGetHandle(inst, 'iRegs0/SurfSet')
SurfHmd = mc.mcRegGetValue(hreg2)
--Set time on Maintinance timer
local hMaint = mc.mcRegGetHandle(inst, 'iRegs0/MaintTime')
local MaintTime = mc.mcRegGetValue(hMaint)
local hRunning = mc.mcRegGetHandle(inst, 'iRegs0/RunningTime')
local RunningTime = mc.mcRegGetValue(hRunning)
MaintTime = (MaintTime + RunningTime)
mc.mcRegSetValue(hMaint, MaintTime)
mc.mcRegSetValue(hRunning, 0.0)
--get offset number
local hregPHN = mc.mcRegGetHandle(inst, 'iRegs0/ProjHmPos')
local ProjHmNum = mc.mcRegGetValue(hregPHN)
--get if in tk mode and if homed
local TKOnOff = mc.mcCntlGetParameter(502)
local TKHmdH = mc.mcSignalGetHandle(inst, mc.OSIG_HOMED_A)
local TKHmdV = mc.mcSignalGetState(TKHmdH)
if (ProjHmNum == 1) then
if (ProjHmd1 == 0) then
wx.wxMessageBox('Please Set Project 1 Home Before Clicking Run')
elseif (SurfHmd == 0) then
wx.wxMessageBox('Please Set Surface Before Clicking Run')
elseif (TKOnOff == 1) and (TKHmdV == 0) then
wx.wxMessageBox('Please Home TK Before Clicking Run')
else
--get and set home 1 offsets
hregX1 = mc.mcRegGetHandle(inst, 'iRegs0/ProjHm1X')
ValX1 = mc.mcRegGetValue(hregX1)
hregY1 = mc.mcRegGetHandle(inst, 'iRegs0/ProjHm1Y')
ValY1 = mc.mcRegGetValue(hregY1)
MachX = mc.mcAxisGetMachinePos(inst, 0)
MachY = mc.mcAxisGetMachinePos(inst, 1)
PosSetX1 = (MachX - ValX1)
PosSetY1 = (MachY - ValY1)
mc.mcAxisSetPos(inst, 0, PosSetX1)
mc.mcAxisSetPos(inst, 1, PosSetY1)
--regenerate toolpath
-- mc.mcToolPathGenerate(inst)
--if machine homed check if file larger than soft limits
hregMHmd = mc.mcRegGetHandle(inst, 'iRegs0/MachHmd')
valMHmd = mc.mcRegGetValue(hregMHmd)
if (valMHmd == 1) then
MaxX = mc.mcAxisGetSoftlimitMax(inst, 0)
MaxY = mc.mcAxisGetSoftlimitMax(inst, 1)
hregPathXMax = mc.mcRegGetHandle(inst, 'core/inst/PathXmax')
PathXmax = mc.mcRegGetValue(hregPathXMax)
hregPathYMax = mc.mcRegGetHandle(inst, 'core/inst/PathYmax')
PathYmax = mc.mcRegGetValue(hregPathYMax)
MinX = mc.mcAxisGetSoftlimitMin(inst, 0)
MinY = mc.mcAxisGetSoftlimitMin(inst, 1)
hregPathXMin = mc.mcRegGetHandle(inst, 'core/inst/PathXmin')
PathXmin = mc.mcRegGetValue(hregPathXMin)
hregPathYMin = mc.mcRegGetHandle(inst, 'core/inst/PathYmin')
PathYmin = mc.mcRegGetValue(hregPathYMin)
if (PathXmax >= MaxX) or (PathYmax >= MaxY) or (PathXmin <= MinX) or (PathYmin <= MinY) then
wx.wxMessageBox("Cut file is outside cut area.\nContinuing may damage machine.")
end
end
mc.mcCntlCycleStart(inst);
end
end
if (ProjHmNum == 2) then
if (ProjHmd2 == 0) then
wx.wxMessageBox('Please Set Project 2 Home Before Clicking Run')
elseif (SurfHmd == 0) then
wx.wxMessageBox('Please Set Surface Before Clicking Run')
elseif (TKOnOff == 1) and (TKHmdV == 0) then
wx.wxMessageBox('Please Home TK Before Clicking Run')
else
--get and set home 2 offsets
hregX2 = mc.mcRegGetHandle(inst, 'iRegs0/ProjHm2X')
ValX2 = mc.mcRegGetValue(hregX2)
hregY2 = mc.mcRegGetHandle(inst, 'iRegs0/ProjHm2Y')
ValY2 = mc.mcRegGetValue(hregY2)
MachX = mc.mcAxisGetMachinePos(inst, 0)
MachY = mc.mcAxisGetMachinePos(inst, 1)
PosSetX2 = (MachX - ValX2)
PosSetY2 = (MachY - ValY2)
mc.mcAxisSetPos(inst, 0, PosSetX2)
mc.mcAxisSetPos(inst, 1, PosSetY2)
--regenerate toolpath
-- mc.mcToolPathGenerate(0)
--if machine homed check if file larger than soft limits
hregMHmd = mc.mcRegGetHandle(inst, 'iRegs0/MachHmd')
valMHmd = mc.mcRegGetValue(hregMHmd)
if (valMHmd == 1) then
MaxX = mc.mcAxisGetSoftlimitMax(inst, 0)
MaxY = mc.mcAxisGetSoftlimitMax(inst, 1)
hregPathXMax = mc.mcRegGetHandle(inst, 'core/inst/PathXmax')
PathXmax = mc.mcRegGetValue(hregPathXMax)
hregPathYMax = mc.mcRegGetHandle(inst, 'core/inst/PathYmax')
PathYmax = mc.mcRegGetValue(hregPathYMax)
MinX = mc.mcAxisGetSoftlimitMin(inst, 0)
MinY = mc.mcAxisGetSoftlimitMin(inst, 1)
hregPathXMin = mc.mcRegGetHandle(inst, 'core/inst/PathXmin')
PathXmin = mc.mcRegGetValue(hregPathXMin)
hregPathYMin = mc.mcRegGetHandle(inst, 'core/inst/PathYmin')
PathYmin = mc.mcRegGetValue(hregPathYMin)
if (PathXmax >= MaxX) or (PathYmax >= MaxY) or (PathXmin <= MinX) or (PathYmin <= MinY) then
wx.wxMessageBox("Cut file is outside cut area.\nContinuing may damage machine.")
end
end
mc.mcCntlCycleStart(inst);
end
end
end
end
end