I've searched and found some explanations for why Mach4 doesn't remember the axis positions when it is shut down and restarted. They make sense but Mach3 used to do it and the examples I found were not working or I did not understand them. After searching and experimenting I came up with a simple way that works for me.
Firsst go to Configure - Plugins - Regfile.
Click on the + and add three new registers: Xpos, Ypos and Zpos.
make sure the persistent colume is green checked.
Next add the following to the screen load script:
---------------------------------------------------------------
-- Get register
---------------------------------------------------------------
function GetRegister(regname)
local inst = mc.mcGetInstance()
local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", regname))
return mc.mcRegGetValueString(hreg)
end
---------------------------------------------------------------
-- Save register
---------------------------------------------------------------
function WriteRegister(regname, regvalue)
local inst = mc.mcGetInstance()
local hreg = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", regname))
mc.mcRegSetValueString(hreg, tostring(regvalue))
end
Next make a new Save button and add the following to the left up script:
posx = scr.GetProperty("droCurrentX","Value")
WriteRegister("Xpos", posx)
posy = scr.GetProperty("droCurrentY","Value")
WriteRegister("Ypos", posy)
posz = scr.GetProperty("droCurrentZ","Value")
WriteRegister("Zpos", posz)
Next make a new Load button and add the following to the left up script:
regvalx = GetRegister("Xpos")
regvalx = tonumber(regvalx)
mc.mcAxisSetPos(inst, mc.X_AXIS,regvalx)
regvaly = GetRegister("Ypos")
regvaly = tonumber(regvaly)
mc.mcAxisSetPos(inst, mc.Y_AXIS,regvaly)
regvalz = GetRegister("Zpos")
regvalz = tonumber(regvalz)
mc.mcAxisSetPos(inst, mc.Z_AXIS,regvalz)
That should be it. Save all changes and When you click the save button it will save positions in the registers. When exiting the registers will be saved in the machine.ini file. When mach4 is restarted click the load button and it will load the positions from the ini file.
If you want it to do it automaticly put the button codes into the screen load script and the screen unload script instead of buttons.
Yes things could move on the machine but this is how Mach3 worked and that was fine. It won't work if Mach crashes but it didn't on Mach3 either.
Hope this helps somebody.