Alrighty,
I've found a solution.
This snippet of code gets the core/inst register of CmdEnable count.
When it is "1" then it will run my SetCurrentTool() function and adds 1 to the CmdEnable register so it doesn't keep looping.
Here is the Screen Load Script and the PLC Script that I'm using to accomplish this task.
--Set Current Tool Screen Load Script.
function SetCurrentTool()
local inst = mc.mcGetInstance()
local ActualTool = wx.wxGetNumberFromUser("What tool is in the turret?", "Tool # ","Current Tool", 1, 1, 6) -- Default, Min, Max.
local rc = ActualTool
if rc == -1 then
wx.wxMessageBox("Set the current tool to the actual tool.")
else
mc.mcToolSetCurrent(inst, ActualTool)
mc.mcCntlSetLastError(inst, "T" .. tostring(ActualTool) .. "0" .. tostring(ActualTool))
mc.mcCntlGcodeExecute(inst, "T" .. tostring(ActualTool) .. "0" .. tostring(ActualTool)) --This uses the Tool Number that was entered into the Dialogue Box and pieces together a T### Command real fast.
end
end--SetCurrentTool()
--Set Current Tool PLC Script
local hReg = mc.mcRegGetHandle(inst, "core/inst/CmdEnable");
local EnableCount = mc.mcRegGetValue(hReg)
if EnableCount == 1 then
SetCurrentTool()
mc.mcRegSetValue(hReg, 2)
end