Put this function in your screenload script
function LoadLastGCode()
local inst = mc.mcGetInstance()
--This prevents a crash if there is already a loaded file e.g. when coming out of the screen editor
local curFile = mc.mcCntlGetGcodeFileName(inst)
if (curFile ~= "") then
do return end
end
--Mach4 already stores last loaded file in the machine.ini, this is used for the 'Load Recent File' button
--So we'll just read the file name and path from here
local fileName = mc.mcProfileGetString(inst, 'Preferences', 'MRU1', 'NO FILE')
--Load the file and check for errors
if (fileName ~= "NO FILE") then
local rc = mc.mcCntlLoadGcodeFile(inst, fileName)
if (rc ~= mc.MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, "Error loading last g-code file")
else
mc.mcCntlSetLastError(inst, "Last G-Code file successfully loaded")
end
else
mc.mcCntlSetLastError(inst, "Last loaded g-code file not found")
end
end
and then at the bottom of the PLC script there is a 'PLC First Run' section. It will look something like this, you'll have some other functions in there as well to do with the keyboard. Just add the call to the function within the 'if' statement.
-------------------------------------------------------
-- PLC First Run
-------------------------------------------------------
if (testcount == 1) then
LoadLastGCode() --Call the function here
...
[/cpde]