B34R
i got this from Steve at New Fangled.
When you are ready to add the message box hope this helps.
Most of the script has been deleted. I left the part about the register that you will need.
Bill
So the issue is that you are launching a wxMessageBox from a macro script. The macro scripts are run from the G code interpreter which is, in turn, run from the thread that loads the look ahead buffers. This is NOT the main thread in the application, the core, or the mcLua plugin. So no GUI functions should ever be launched from a macro script. Also, the wxMessageBox() call really wants to have a parent window launch it. There is no parent window in a macro script. So what modal state does it take on? The answer is undefined behavior, as in “we won’t know”.
I understand the allure of wxMessageBox(). It is simple and easy to use. But It just is never a good idea to use it in a macro script. In fact, I wish I could take it out of wxLua completely because of this situation. But what needs to be done is launch the wxMessageBox() from a main thread such as the Mach4GUI’s PLC script.
1. Replace the wxMessageBox() calls in the macro script with “set and wait on clear” register flags.
2. In the Mach4GUI’s PLC script, watch for the register to become set and launch the wxMessageBox().
3. Once the user dispenses with the message box, clear the register.
4. The macro script sees that the register is clear and continues on.
Here is the semi complete example for the macro script:
function m60()
inst = mc.mcGetInstance() -- Get the current instance
local rc -- Check the API return codes!!!! There are no mysteries if you do.
--check for manual cut and wait if manual cut on
local hregC, rc = mc.mcRegGetHandle(inst, 'iRegs0/ManCut')
if (rc != mc.MERROR_NOERROR) then
-- this will abort the G code process. Reset will have to be issues to clear the alarm.
mc.mcCntlMacroAlarm(inst, 0, "m60: Cannot get the handle to ManCut");
return
end
local waitReg, rc = mc.mcRegGetHandle(inst, 'iRegs0/WaitFlag')
if (rc != mc.MERROR_NOERROR) then
-- this will abort the G code process. This will just stop the file.
mc.mcCntlMacroStop(inst, 1, "m60: Cannot get the handle to ManCut");
return
end
-- I will leave the rest of the error checking as your exercise.
local ManualCut = mc.mcRegGetValue(hregC)
if (ManualCut == 1) then
mc.mcRegSetValue(waitReg, 1) -- set the register.
--wx.wxMessageBox("Press Manual Cut Button")
while (mc.mcRegGetValue(waitReg) == 1) do -- wait for it to clear.
wx.wxMilliSleep(10)
end
end
while (ManualCut == 1) do
wx.wxMilliSleep(100)
ManualCut = mc.mcRegGetValue(hregC)
Steve