Thanks Bill, I was able to get it working although I wasn't able to use the "Aux Position" function of Mach4 V2. Instead I set up a dummy axis and used the API calls that are documented.
Unfortunately, with the release of V2 and all the updates it brings there doesn't seem to be much in the way of documentation, the Core API help file included in the installation seems to be from 2017, long before V2.
This is the code I added to the PLC script;
---------------------------------------------------------------
-- Check for Table move and update Table Position
---------------------------------------------------------------
local Cpos = mc.mcAxisGetMachinePos(inst, 5)
local ZheadShift = mc.mcCntlGetPoundVar(inst, mc.SV_HEAD_SHIFT_Z)
local TablePosReg = mc.mcRegGetHandle(inst, 'iRegs0/TablePosition')
local homedC=mc.mcAxisIsHomed(inst,mc.C_AXIS)
if (homedC ~= 0) and (Cpos ~= ZheadShift) then
mc.mcCntlSetPoundVar(inst, mc.SV_HEAD_SHIFT_Z, Cpos)
mc.mcRegSetValue(TablePosReg, Cpos)
end
---------------------------------------------------------------
-- End of Check for Table move and update Table Position
---------------------------------------------------------------
And this code to the refAllHome() function in the screen load script;
---------------------------------------------------------------
-- Load Previous Table Position
---------------------------------------------------------------
local TablePosReg = mc.mcRegGetHandle(inst, 'iRegs0/TablePosition')
local TablePos = mc.mcRegGetValue(TablePosReg)
mc.mcCntlSetPoundVar(inst, mc.SV_HEAD_SHIFT_Z, TablePos)
mc.mcAxisSetHomeOffset(inst, 5, TablePos)
---------------------------------------------------------------
-- End of Load Previous Table Position
---------------------------------------------------------------