Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: Cbyrdtopper on December 21, 2017, 09:22:21 AM
-
So the simple wx.messagebox is great. But is there a wx.widget that gives me a message box with "Okay" and "Cancel" as options to choose?
-
local rc = wx.wxMessageBox("This is my Message", "This is my Caption",16) --Ok, Cancel
--wxMessageBox Types
--2 = Yes, No
--4 = Ok
--16 = Ok, Cancel
--18 = Yes, No, Cancel
--wxMessageBox Return Values
--Yes = 2
--OK = 4
--No = 8
--Cancel = 16
-
Yes! Awesome, I'm going to try this once I get back to the shop today.
-
So, I've got another message box question.
Is there a way I can have a user type in a number in a message box, and then use that number to set an offset?
-
Sure is..........
local MyNum = wx.wxGetNumberFromUser("Message", "Prompt", "Caption", 50, 0, 100) --Default, min, max
Or you can get it as a string and then convert it to a number. Can do some checks with either, flip numbers, etc. Goods and bads using both methods. Just have to figure out what works best for you and your condition.
local MyText = wx.wxGetTextFromUser("Message", "Caption", "Default Value")
-
Okay. Very nice. I'll have to play with it and see what works well.
Just to let you know what I'm trying to accomplish:
On the lathe we are retrofitting, I want to prompt the operator on startup to enter the current tool in the turret. Just in case Mach4 is shut down before retaining the current tool.
-
Excellent!
Works perfectly! Since I'm using a number. wx.wxGetNumberFromUser works great!
-
Do you know what the Return Values are for this, I can't seem to find them? If the operator hits "cancel" I want to Pop up the User Input Box again.
-
Okay, So, I've found the Return Value I need. But how do I get my syntax correct.
local ActualTool, rc = wx.wxGetNumberFromUser()
if rc == -1 then
mc.mcCntlSetLastError(inst, "ERROR")
else
mc.mcToolSetCurrent(inst, ActualTool)
end
This isn't working correctly. When I hit cancel, it puts a "-1" in my current tool and skips over the if rc == -1
Obviously I have something wrong.
If I just have rc =wx.wxGetNumberFromUser() everything works properly. But I wold rather have the variable "Actual Tool" instead of just "rc"
-
I'm not sure if this is the "correct" way to do this. But it works for my proof of concept.
--What is the current tool?
function m110()
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)
end
end --m110
if (mc.mcInEditor() == 1) then
m110()
end
-
I'm not sure what your exact flow is but you may need to do a couple of message boxes. One ask a question........ then pop up next based on response. Could have lots of options for next. Might even need more steps which = more message boxes. I hope that makes sense.
-
Correct me if i'm wrong but wx.wxGetNumberFromUser() only works with integers.
hth
rt
-
Brett,
I only put the 2nd wx.wx.messagebox in there to test with. I will make it loop until the operator puts a number in there, I'm forcing them to set the current tool to the actual tool in turret rather than just assuming the operator will be sure to put the correct tool number in the DRO. This code will run only on the start up.
Speaking of running only 1 time.
I put this in the "First Run PLC Script." It didn't crash and as far as I can tell it didn't alter anything else. Is that okay? Or is there a better way to make something run only on startup? Open to any and all suggestions.
Also, I thought we could use Global Variables (like "testcount" in PLC Script) everywhere, even in a macro. It won't let me.
-
Correct me if i'm wrong but wx.wxGetNumberFromUser() only works with integers.
hth
rt
I'm using this to get the "Actual Tool" that is in the turret, so all I need is the integer.
This box pops up, the operator looks at the turret sees that "Tool #" is the current tool, they type it in the message box and it updates the Current Tool DRO.
-
Yes, but you asked also asked for a way to ask the user for a number for a 'position'. Thought I would save someone in the future reading this thread some time so they don't try it for that.
-
Yes, but you asked also asked for a way to ask the user for a number for a 'position'. Thought I would save someone in the future reading this thread some time so they don't try it for that.
Gotcha! ;)
-
I put this in the "First Run PLC Script." It didn't crash and as far as I can tell it didn't alter anything else. Is that okay? Or is there a better way to make something run only on startup? Open to any and all suggestions.
Yes, that is acceptable. I would build the function in the screen load script and call that function only once from the PLC script by doing like you have in first run or maybe even third run.
Also, I thought we could use Global Variables (like "testcount" in PLC Script) everywhere, even in a macro. It won't let me.
I like calling them regionally global. ;D
Macros and screens run in 2 different instances so ones global is not global to the other. The only thing (that i know of) right now that is global global are registers. They can be read and written to from the screen, macros, modules, lua panels, etc.
-
I put this in the "First Run PLC Script." It didn't crash and as far as I can tell it didn't alter anything else. Is that okay? Or is there a better way to make something run only on startup? Open to any and all suggestions.
I like calling them regionally global. ;D
Brett, I like it! lol :)
I thought about making a function. It would make it a little cleaner. I'll give that a try next.
-
This is working great!
I went ahead and made it a function in the screen load script; just to tidy things up.
I also put it on the 25th scan.
if testcount == 25 then
SetActualTool()
end
It was popping up right as Mach4 was initializing, and it was hiding it behind Mach. So, moved it to 25 and it pops up on the screen just fine, in about 1.5 seconds.
-
:)
-
So,
to make this loop, I was going to do something like this:
while rc == -1 do
local ActualTool = wx.wxGetNumberFromUser()
local rc = ActualTool
end
but it won't change the rc inside the loop. I changed the variable name to Test and it returned an ERROR. Why is that?
While writing this reply, I was testing the loop again. It isn't even changing my variable ActualTool from the GetNumberFromUser.
-
Try using the repeat command like this
local inst = mc.mcGetInstance()
repeat
local ActualTool = wx.wxGetNumberFromUser("What tool is in the turret?", "Tool # ","Current Tool", 1, 1, 6) -- Default, Min, Max.
until ActualTool ~= -1
--mc.mcToolSetCurrent(inst, ActualTool)
wx.wxMessageBox(tostring(ActualTool))
DazTheGas
-
Thanks Daz. That's exactly what I was looking for. I had no idea that command even existed!! :)
-
Thanks Daz. That's exactly what I was looking for. I had no idea that command even existed!! :)
You will love this then.......
http://www.lua.org/manual/5.2/
-
Hi,
Chaoticone's link to the Lua 5.2 manual is great, I usually have it open when I'm doing any coding, I still have to delve into it a lot.
Just be warned there is a Lua 5.3 and some things change and can and will trip you up if you blithely believe that Mach can handle 5.3.
Craig
-
Thanks for the info, Brett and Craig.
I've looked through that manual before. I don't know why I didn't think to look for a "Repeat" command. Couldn't see the forest for the trees I guess.
Craig,
I'm guessing Mach uses the 5.2 stuff then?
-
HAHAHAHA Once youve finished with the Lua Manual you can then move on to wxLua Manual :o ;D :D ;)
DazTheGas
-
HAHAHAHA Once youve finished with the Lua Manual you can then move on to wxLua Manual :o ;D :D ;)
DazTheGas
Very true Daz. If the reference manual makes you happy the wxLua manual might put you over the edge. ;D
In the reference manual, look at http://www.lua.org/manual/5.2/manual.html#9
-
After testing the "Repeat" Command. It isn't working as expected. When I run through the code, it returns an ERROR when it reads "while actualtool ~=1" After I input a number in the box, it reads that number just fine. But as soon as the debugger gets on the "While" line, it returns an ERROR in the ActualTool Variable.
-
post the whole code you are using as I have tested what i posted and all works.
DazTheGas
-
Daz,
Here is my entire macro. The repeat command works, to test this I kept hitting cancel and it pops back up as expected.
However, when I input a number, it acknowledges that number until it reads the "until" line, then the variable "ActualTool1" returns an ERROR instead of #.
--What is the actual tool?
function m110()
local inst = mc.mcGetInstance()
repeat
local ActualTool1 = wx.wxGetNumberFromUser("What tool is in the turret?", "Tool # ","Current Tool", 1, 1, 6) -- Default, Min, Max.
until (ActualTool1 ~= -1)
mc.mcToolSetCurrent(inst, ActualTool1)
end --m110
if (mc.mcInEditor() == 1) then
m110()
end
-
Oh I see now, der me.... you cannot run any of the getnumberfromuser or textfromuser from a macro. just remembered I tried to use this a while back. the lua stack is a cutdown version and wont allow dialogs like this.
DazTheGas
-
This was allowing me to get text and numbers and use them. Just not inside the repeat command.
-
You might try this.... instead of doing the repeat loop in the macro, have a separate function to check the number entered and another function to pop up the message box if needed.
-
Here you go http://www.dazthegas.co.uk/forumanswers/m110.mp4 perhaps this will explain the error i was on about.
DazTheGas
-
Daz,
Thanks for the video. I had that error pop up yesterday, didn't know what it was. I'm guessing once you close it out the first time, you're good to go until Mach gets shutdown and turned back on again?