Hi Chad,
the only real difficulty in opening existing files or creating new ones is using/having a file dialog which means wxLua.
In the LuaExamples folder are two macros m400() and m401() which are opening, creating and populating a probe file.
The file dialog code I use and have reused is just an edited version of that code.
-- create the wxFrame window
mainframe = wx.wxFrame( wx.NULL, -- no parent
wx.wxID_ANY, -- whatever for wxWindow ID
"DummyFrame", -- frame caption
wx.wxDefaultPosition, -- place the frame in default position
wx.wxDefaultSize, -- default frame size
wx.wxDEFAULT_FRAME_STYLE ) -- use default frame styles
-- create a panel in the frame
panel = wx.wxPanel(mainframe, wx.wxID_ANY)--We are not going to show it but we need to have this to use the File dialog
local file = wx.wxFileDialog(panel, "Select Data File", "", "", "Text files (*.txt)|*.txt|Tap files (*.tap)|*.tap",
wx.wxFD_SAVE,wx.wxDefaultPosition,wx.wxDefaultSize, "File Dialog" );
if(file:ShowModal() == wx.wxID_OK)then
path = file:GetPath()
outfile=assert(io.open(tostring(path),'w+'))
end
This is an example of that code. Note that the frame and panel are nothing special but they need to be present so the
file dialog can happen. This is the critical line:
local file = wx.wxFileDialog(panel, "Select Data .....................................................faultSize, "File Dialog" );
The remaining code is all about using functions of the data structure "file", for instance:
file:ShowModal() == wx.wxID_OK and:
path = file:GetPath()
The line which opens the file is:
outfile=assert(io.open(tostring(path),'w+')) but that is inelegant, this is an example of a file opening statement
that I wrote for a job a week or so ago:
local fileHandle=io.open(pathfilename,"w+") and some of the statements for writing to, flushing and closing the
file using this syntax are:
fileHandle:write(offset,'\n')
fileHandle:flush()
fileHandle:close()
I'm sort of thinking that opening and closing files is getting a bit away from the subject of this thread and am likely to confuse
the hell out of OP if I start posting code in the same thread. I will start a new thread where I will write the generated Gcode
to a file, sort of a poor mans Wizard.
Craig.