Hello Guest it is April 12, 2026, 09:33:39 AM

Author Topic: Assign Button to Call M132  (Read 1171 times)

0 Members and 1 Guest are viewing this topic.

Assign Button to Call M132
« 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.
Re: Assign Button to Call M132
« Reply #1 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.
Thanks,

Paul
Re: Assign Button to Call M132
« Reply #2 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.
Re: Assign Button to Call M132
« Reply #3 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.
Thanks,

Paul
Re: Assign Button to Call M132
« Reply #4 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.
Re: Assign Button to Call M132
« Reply #5 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")

Thanks,

Paul
Re: Assign Button to Call M132
« Reply #6 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.
Thanks,

Paul
Re: Assign Button to Call M132
« Reply #7 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.
Re: Assign Button to Call M132
« Reply #8 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.
Thanks,

Paul
Re: Assign Button to Call M132
« Reply #9 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.
Thanks,

Paul