Machsupport Forum

MachPro => MachPro General Discussion => Topic started by: tbadger on March 15, 2026, 02:58:28 PM

Title: Assign Button to Call M132
Post by: tbadger on March 15, 2026, 02:58:28 PM
I've got a RapidChange Solo ATC setup on my CNC. To probe for Z zero, I now use M132. I'd like to create a button on one of the dashboards to call this M code. But in reviewing all options (that I can find), there is no clear way to do this, except to create a user script.

The documentation here, https://support.machmotion.com/books/shared-content-public-f71/page/machpro-widgets-dashboard-commands-and-function-buttons#bkmrk-user-commands  is somewhat vague IHMO on what can be done.  It states the following:

Quote
One option for user commands are User Scripts. These are lua functions that will be executed as the command, to get the feedback state, or to forward to the target. This is a way to create completely custom functionality. They should always be done in the UserGUIModule.UserStartUpScript function. The following is an example of how to create these lua function in the UserGUIModule.

Within the Profile > Router > Macros > Scripts folder, there are several files that might be the right candidate, but which one is unclear. In none of those files is the section (or function) labeled UserGUIModule.UserStartUpScript.

Is this still a work in progress, or is there something that I may have missed, or is there a better way to have a button call and execute M132?

My preference is that on pressing the button, it will call M132 and CycleStart if that is necessary.  My only option right now is to use MDI and CycleStart, which is really inconvenient.
Title: Re: Assign Button to Call M132
Post by: paul.stephens on March 17, 2026, 02:54:13 PM
Go to Mach\Profile\{Profile name}\ Macros\Scripts
Here you will make a copy of UserMCodeModuleDefault.mcs and rename the copy to UserMCodeModule.mcs

From here, you can start editing the file.

Add your function in like below

function UserMCodeModule.m132()

    --insert user data here..

end

This will add your macro to your MCodes.

On the side note, we are in the process of adding the RapidChange ATC to our list of Tool Changers in the core of mach. I expect 1-2 weeks for this.
Title: Re: Assign Button to Call M132
Post by: tbadger on March 17, 2026, 03:04:04 PM
Thanks for the reply Paul. I'm a beta tester, so hope to see the RapidChange ATC code earlier than later. I may watch for it in the Development branch. As there are at least three varieties of ATCs from them (ATC, STC, and MTC), should I expect to see all of them included in the initial release?  Having a Solo, that is what I'm most interested in.
Title: Re: Assign Button to Call M132
Post by: paul.stephens on March 17, 2026, 03:31:04 PM
That would be up to the RapidChange team as the ball is currently in their court. I assume they would add logic for all of their current varieties.
Title: Re: Assign Button to Call M132
Post by: tbadger on March 17, 2026, 11:43:16 PM
I failed to note that I’m running the Solo ATC on Mach 4 right now, and have already set up a button that will execute the M132 macro. Unless they are creating something specific that follows the MachPro model for ease of configuration for their new macros, this is the likely route to go. I just needed to know where to inject the macro call.
Title: Re: Assign Button to Call M132
Post by: paul.stephens on March 18, 2026, 10:21:19 AM
Ahh I see..

To add a button in your dashboard for this, go to Go to Mach\Profile\{Profile name}\ Macros\Scripts.
Here you will make a copy of UserGUIModuleDefault.mcs and rename the copy to UserGUIModule.mcs

In that script, you're going to go to the bottom You'll see some things about CreateUserCommands()

You'll just need something along these lines to add a dashboard button.
Code: [Select]
function UserGUIModule.CreateUserCommands()
    local function RunM(code)
        -- fire and return immediately; the m-code handles any waiting/prompting
        w.api("mcCntlMdiExecute", inst, code)
    end
    w.CreateSimpleCommand("ATC") -- this creates the button and names it
    w.CreateCommandActionOption("ATC", function() RunM("M132") end) -- this gives the button logic
end

There are some other advanced things you can do with it as well like w.CreateCommandFeedbackOption for providing feedback to another function, for example if I wanted 3 different buttons to toggle between eachother, I could use this function to handle the logic for that.
Short parameter example:
w.CreateCommandFeedbackOption("ATC", function() return UserGUIModule.IsM312() end)

Another option is if you want the button to change colors when toggled

w.SetCommandButtonColors("ATC", "#FF0000", "#00FF00")

A third optional function is if you want to change the label name as it toggles.

w.SetCommandButtonLabels("ATC", "M132 off", "M132 on")

Title: Re: Assign Button to Call M132
Post by: paul.stephens on March 18, 2026, 10:24:18 AM
Once you have the button logic existing, your Dashboard should have it available once Mach is recompiled or restarted. Just Configure Widget, change your button and find the Button pressed option you just created.
Title: Re: Assign Button to Call M132
Post by: tbadger on March 18, 2026, 11:33:24 AM
Awesome info, thanks.  I've been getting quite comfortable with the Dashboard/Widget/Button setup. By simply adding an output, I've seen how easy it can be to add a button for On/Off or Toggle. Or just finding existing functions that I can easily add as buttons. 

My next feature request is to add a new dashboard component that I can put on the left side of the GCode tab, or any where I want/need one.  I've removed all of the existing lower buttons and moved them to the Side Dashboard. I have a touch screen, and am right handed. So I like all of the functional buttons I use in one place. The Dashboard makes this extremely easy.
Title: Re: Assign Button to Call M132
Post by: paul.stephens on March 18, 2026, 12:16:38 PM
Technically there is, the dashboard is a "Plugin Panel". So you can technically add a Dashboard wherever you want. The issue is that we have not designed a modular dashboard to just be thrown everywhere. So you're stuck with however that particular dashboard is hard coded to be designed as for the moment. We are planning on a resolution for this, but at this moment, that will probably be after we move to a more web based UI.
Title: Re: Assign Button to Call M132
Post by: paul.stephens on March 18, 2026, 12:25:17 PM
On a side note, you can add a Control Box if you wish next to your Gcode by going to Service → Maintenance → Screen Config, Inside of your Control Group, Select Show All.
Title: Re: Assign Button to Call M132
Post by: paul.stephens on March 18, 2026, 12:34:20 PM
Just a warning as well, at this time, if you add a new dashboard, it will mimic the dashboard you selected. Basically at this time there is only one instance of a dashboard type. For example, if I added a duplicate dashboard type like in the image, all elements will reflect the other dashboard. So a change to one will change the other.
Title: Re: Assign Button to Call M132
Post by: tbadger on March 18, 2026, 02:01:03 PM
Yep - I've explored the implementation a bit and can confirm your comments. For now, the Control Group is hidden, which I had discovered in the screen config. The File group is hidden in the Screen set for now.
Title: Re: Assign Button to Call M132
Post by: cd_edwards on May 17, 2026, 06:21:18 PM
Can I assume that if the button ends up being Red, it's bad?
Title: Re: Assign Button to Call M132
Post by: tbadger on May 17, 2026, 08:40:19 PM
Screenshot?  Does it go red even though you've set the colors to something else?  Is it Red when the system is enabled or disabled?
Title: Re: Assign Button to Call M132
Post by: cd_edwards on May 18, 2026, 06:36:20 AM
here's a pic.


and the function. It's probably something stupid I've done.

function UserGUIModule.CreateUserCommands()
    local function RunM(code)
        -- fire and return immediately; the m-code handles any waiting/prompting
        w.api("mcCntlMdiExecute", inst, code)
    end
    w.CreateSimpleCommand("DustBoot") -- this creates the button and names it
    w.CreateCommandActionOption("DustBoot", function() RunM("m2221") end) -- this gives the button logic
   w.SetCommandButtonColors("DustBoot", "#FF0000", "#00FF00")
   w.SetCommandButtonLabels("Dustboot", "DustBoot on", "DustBoot off")
end
Title: Re: Assign Button to Call M132
Post by: cd_edwards on May 18, 2026, 07:57:22 AM
Now I'm getting somewhere. Just need to figure out why it's not running the scripts. My goal here is to create a button that will dock a dust boot and pick it up again. The Signal needs to be setup within the Mach Outputs, and assigned to the function AutoDustBoot. Signal 100 is arbritrary. Button now toggles back and forth and toggles color. I believe that the color's Paul showed were Red and Green and along with everything else was just confusing. There are probably much better ways of doing this. But for now, this works. A register that saves would be ideal, but then it's a whole nother ball of wax. Next I'll work on a probe autoload function.


function UserGUIModule.CreateUserCommands()
    local function RunM(code)
        -- fire and return immediately; the m-code handles any waiting/prompting
       local state = w.GetSignalState(mc.OSIG_OUTPUT100)

       if state == 1 then
          w.api("mcCntlMdiExecute", inst, "m2222")
       else
          w.api("mcCntlMdiExecute", inst, "m2223")
       end
 ---       w.api("mcCntlMdiExecute", inst, code)
        w.SetSignalState(mc.OSIG_OUTPUT100, not state)
    end
    w.CreateSimpleCommand("AutoDustBoot") -- this creates the button and names it
    w.CreateCommandActionOption("AutoDustBoot", function()RunM("AutoDustBoot") end) -- this gives the button logic
--   w.SetCommandButtonColors("AutoDustBoot", "#FF0000", "#00FF00")
   w.SetCommandButtonLabels("AutoDustBoot", "DustBoot on", "DustBoot off")
   return true, true, w.FunctionCompleted()
end
Title: Re: Assign Button to Call M132
Post by: paul.stephens on May 18, 2026, 09:42:28 AM
Yes, the example I had shown were very custom and designed for a lathe with three separate running states. So there were three different buttons interacting with each other. I'll try to create easier examples in the future. That was just the example I had available at the time.

SetCommandButtonColors Sets your label colors based if it is activated or deactivated.
Here is our documented info on it. The color codes are Hex color codes.

---------------------------------------------------------------------------------
WrapperModule SetCommandButtonColors   (   cmd_name   ,
off_color   ,
on_color    )
Set the on and off background colors for a command's button.

Updates the BgOffColor and BgOnColor fields of the command entry in m.Commands. Has no effect if m.Commands is nil or the command does not exist.

Parameters
cmd_name   (string) The name of the command whose button colors are to be set
off_color   (string) The background color when the command feedback state is off (e.g., "#FFFFFF")
on_color   (string) The background color when the command feedback state is on (e.g., "#00FF00")

Title: Re: Assign Button to Call M132
Post by: cd_edwards on May 18, 2026, 09:47:16 AM
my problem was the color code. It would be nice if the color picker would specify the hex color code. Might make it easiler than doing a screen shot, putting into paint and using the color picker edit to find the hex value. :)
Title: Re: Assign Button to Call M132
Post by: cd_edwards on May 18, 2026, 09:55:45 AM
and of course there's the problem that we never run the mcode script. I'm loathe to add it into the UserMCodeModule.

Also, what's the differance between these two functions? Other than the _

function UserMCodeModule.m222(hVars)
   return true, true, w.FunctionCompleted()
end

function UserMCodeModule._m225(hVars)
   return true, true, w.FunctionCompleted()
end

function UserMCodeModule.LubeSystem()
   return true, true, w.FunctionCompleted()
end
There is already a script for this. Do these cascade? one after another or would this replace LubeSystem.mcs?