Hello Guest it is April 13, 2021, 01:29:11 PM

Author Topic: load g code  (Read 222 times)

0 Members and 1 Guest are viewing this topic.

Offline Bill_O

*
  •  362 362
    • View Profile
load g code
« on: August 07, 2020, 10:20:39 AM »
The Load G Code button brings up a screen to select the file. (Gcode Load action)
I want to do the same thing using Lua script.
The mc.CntlLoadGcodeFile requires the file name.

Bill
Re: load g code
« Reply #1 on: August 08, 2020, 06:14:10 AM »
Hi,
you need to use a wxWidgets File dialog.

There is an example in this file:

"C:\Mach4Hobby\LuaExamples\ProbeToFile\m401.mcs"

Craig
My wife left with my best friend...
     and I miss him!

Offline Bill_O

*
  •  362 362
    • View Profile
Re: load g code
« Reply #2 on: August 10, 2020, 08:55:51 AM »
Craig,

Thank you.

Bill

Offline Bill_O

*
  •  362 362
    • View Profile
Re: load g code
« Reply #3 on: August 10, 2020, 10:03:34 AM »
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.

Code: [Select]
---------------------------------------------------------------
-- 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

Re: load g code
« Reply #4 on: August 10, 2020, 11:03:39 AM »
Change wx.wxFD_SAVE to wx.wxFD_OPEN, it will change the button on the dialog from Save to Open

Offline Bill_O

*
  •  362 362
    • View Profile
Re: load g code
« Reply #5 on: August 10, 2020, 11:49:44 AM »
Swifty,

I did not notice that.

Thanks,

Bill