Here is the code I ended up with.
At the end is some code that pops up a message box to let the operator know that the file is outside the machine limits if they set Home All.
---------------------------------------------------------------
-- Load file function.
---------------------------------------------------------------
function LoadCCIFile()
inst = mc.mcGetInstance();
-- 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 Cutting File", "", "", "All files (*.*)|*.*|CNC files (*.cnc)|*.cnc|Tap files (*.tap)|*.tap|Text files (*.txt)|*.txt",
wx.wxFD_SAVE,wx.wxDefaultPosition,wx.wxDefaultSize, "File Dialog" );
if(file:ShowModal() == wx.wxID_OK)then
local path = file:GetPath()
mc.mcCntlLoadGcodeFile(inst, path);
--regenerate toolpath
mc.mcToolPathGenerate(inst)
end
--if machine homed check if file larger than soft limits
hregMHmd = mc.mcRegGetHandle(inst, 'iRegs0/MachHmd')
valMHmd = mc.mcRegGetValue(hregMHmd)
if (valMHmd == 1) then
MaxX = mc.mcAxisGetSoftlimitMax(inst, 0)
MaxY = mc.mcAxisGetSoftlimitMax(inst, 1)
hregPathXMax = mc.mcRegGetHandle(inst, 'core/inst/PathXmax')
PathXmax = mc.mcRegGetValue(hregPathXMax)
hregPathYMax = mc.mcRegGetHandle(inst, 'core/inst/PathYmax')
PathYmax = mc.mcRegGetValue(hregPathYMax)
MinX = mc.mcAxisGetSoftlimitMin(inst, 0)
MinY = mc.mcAxisGetSoftlimitMin(inst, 1)
hregPathXMin = mc.mcRegGetHandle(inst, 'core/inst/PathXmin')
PathXmin = mc.mcRegGetValue(hregPathXMin)
hregPathYMin = mc.mcRegGetHandle(inst, 'core/inst/PathYmin')
PathYmin = mc.mcRegGetValue(hregPathYMin)
if (PathXmax >= MaxX) or (PathYmax >= MaxY) or (PathXmin <= MinX) or (PathYmin <= MinY) then
wx.wxMessageBox("Cut file is outside cut area.\nContinuing may damage machine.")
end
end
end