Hello Guest it is May 27, 2025, 02:49:43 PM

Author Topic: Button script  (Read 5545 times)

0 Members and 1 Guest are viewing this topic.

Button script
« on: September 09, 2024, 05:51:18 AM »
Hello everyone,
Using Chatgpt, I made two scripts m103.mcs and m105.mcs for starting and stopping a milling spindle on a lathe.
Calling functions in a g-code works perfectly as well as in the MDI. Display in addition to a confirmation message of the function ...

Unfortunately, I can not hang this script to a button on my screen with the LUA editor.
Does anyone have an idea please?  :)
« Last Edit: September 09, 2024, 05:55:14 AM by c.r.conception@free.fr »
Re: Button script
« Reply #1 on: September 09, 2024, 06:50:59 AM »
Hello everyone,
Using Chatgpt, I made two scripts m103.mcs and m105.mcs for starting and stopping a milling spindle on a lathe.
Calling functions in a g-code works perfectly as well as in the MDI. Display in addition to a confirmation message of the function ...

Unfortunately, I can not hang this script to a button on my screen with the LUA editor.
Does anyone have an idea please?  :)
« Last Edit: September 09, 2024, 07:09:46 AM by c.r.conception@free.fr »
Re: Button script
« Reply #2 on: September 09, 2024, 09:14:02 AM »
You can use almost the exact same code inside the button.
You don't need the very first "function" or the "end" for the function.
Everything else in between those lines will be fine.

Attached is a picture highlighting a button that I am using for testing. 
Select the button
Notice on the left the little square with the lightning bolt, select that.  This is where you can put your code.  There are several options. 
I usually put code in the "Clicked Script".  Normally that will suffice.  But you can look at the clicked actions and see what you can do without any code as well.
Also, it looks like you're turning on an output.  You can have another button turn that output off, or use the same button to toggle the output on and off with some more code.
Chad Byrd
Re: Button script
« Reply #3 on: September 10, 2024, 12:30:31 AM »
Hello everyone,
Using Chatgpt, I made two scripts m103.mcs and m105.mcs for starting and stopping a milling spindle on a lathe.
Calling functions in a g-code works perfectly as well as in the MDI. Display in addition to a confirmation message of the function ...

Unfortunately, I can not hang this script to a button on my screen with the LUA editor.
Does anyone have an idea please?  :)
To attach your `m103.mcs` and `m105.mcs` scripts to a button in Mach4, first define Lua functions to execute the M-codes using `mc.mcCntlGcodeExecuteWait(inst, "M103")` and `mc.mcCntlGcodeExecuteWait(inst, "M105")`. Then, in the Screen Editor, add a button and set its script to call these functions. Finally, save your changes and test the button to ensure it correctly starts and stops the spindle.
« Last Edit: September 23, 2024, 02:37:22 AM by Tweakie.CNC »
Re: Button script
« Reply #4 on: September 10, 2024, 03:50:56 AM »
You can use almost the exact same code inside the button.
You don't need the very first "function" or the "end" for the function.
Everything else in between those lines will be fine.

Attached is a picture highlighting a button that I am using for testing. 
Select the button
Notice on the left the little square with the lightning bolt, select that.  This is where you can put your code.  There are several options. 
I usually put code in the "Clicked Script".  Normally that will suffice.  But you can look at the clicked actions and see what you can do without any code as well.
Also, it looks like you're turning on an output.  You can have another button turn that output off, or use the same button to toggle the output on and off with some more code.

Perfect ! Thank you very much ! I now know how to operate my button  :)
I have a card with 8 relays, I will be able to add other functions to the retrofit of my turn.  ;D

Re: Button script
« Reply #5 on: September 10, 2024, 04:10:40 AM »
Hello everyone,
Using Chatgpt, I made two scripts m103.mcs and m105.mcs for starting and stopping a milling spindle on a lathe.
Calling functions in a g-code works perfectly as well as in the MDI. Display in addition to a confirmation message of the function ...

Unfortunately, I can not hang this script to a button on my screen with the LUA editor.
Does anyone have an idea please?  :)
To attach your `m103.mcs` and `m105.mcs` scripts to a button in Mach4, first define Lua functions to execute the M-codes using `mc.mcCntlGcodeExecuteWait(inst, "M103")` and `mc.mcCntlGcodeExecuteWait(inst, "M105")`. Then, in the Screen Editor, add a button and set its script to call these functions. Finally, save your changes and test the button to ensure it correctly starts and stops the spindle.

Thanks for your help charliejone, My mistake was in the script header and I didn't write it in the "Clicked Script" box. I have to find in the documentation the exact function of each box to learn more  ;)
« Last Edit: September 23, 2024, 02:38:04 AM by Tweakie.CNC »