This is a pretty good start I think. Put the function in the screen load script and call it with buttons whose clicked scripts are
GetTeachPoint("G1 ") --for a feed move
GetTeachPoint("G0 ") --for a rapid move
Will need a function to start a new file (which would include feed rate) and a function to finish the file or edit and rename the file manually. Not sure when I will get time to look at it again.
inst = mc.mcGetInstance()
function GetTeachPoint(mode) --"G1 " or "G0 "
local AxisTable = {
[1] = 'X',
[2] = 'Y',
[3] = 'Z',
[4] = 'A',
[5] = 'B',
[6] = 'C'}
local MyGcode = mode
for i,v in ipairs (AxisTable) do
local pos = tostring(mc.mcAxisGetPos(inst, (i - 1)))
MyGcode = MyGcode .. string.format(v .. "%0.4f ", pos)
end
MyGcode = MyGcode .. string.format("\n")
local Teach = wx.wxGetCwd() .. "\\GcodeFiles\\Teach.tap" --Define the file name and location
--file = io.open(Teach, "w+") --Open the file in update mode, all previous data is erased
file = io.open(Teach, "a+") --Append update mode, previous data is preserved, writing is only allowed at the end of file.
file:write (MyGcode) --Write the Gcode file
file:flush (Teach) --Save written data
file:close (Teach) --Close file
end