function m402() inst = mc.mcGetInstance() local X = mc.mcAxisGetPos (inst, mc.X_AXIS) local Y = mc.mcAxisGetPos (inst, mc.Y_AXIS) local Z = 0 local MyGcode = string.format("%0.3f, %0.3f, %0.3f \n", X, Y, Z) local Points = wx.wxGetCwd() .. "\\GcodeFiles\\Points.txt" --Define the file name and location file = io.open(Points, "a+") --Append update mode, previous data is preserved file:write (MyGcode) --Write the Gcode file file:flush (Points) --Save written data file:close (Points) --Close file end if (mc.mcInEditor() == 1) then m402() end