Hello Guest it is March 11, 2026, 11:04:27 AM

Author Topic: Macros not compiling or executing - no .mcc files created on startup  (Read 200 times)

0 Members and 2 Guests are viewing this topic.

Hi all,
It's my first post, so please accept my apologies if I should have posted this somewhere else.  I have a custom 5-axis router running Mach4 4.2.0.4300 with a PoKeys57CNC motion controller. My profile (johnny5) was created using the PoKeys setup wizard and uses the wx6 screenset.
I am unable to get any macros to execute. I have tried M6 and M30. Both are silent — no errors, no popups, nothing. The macro files are in C:\Mach4Hobby\Profiles\johnny5\Macros\ and are correctly structured Lua scripts following the standard format:

luafunction m6()
    inst = mc.mcGetInstance()
    mc.mcCntlSetLastError(inst, "test")
end

if (mc.mcInEditor() == 1) then
    m6()
end

Files are saved with ANSI encoding. ZeroBrane compiles them with no errors. However no .mcc files are ever created in the macros folder after restarting Mach4.
The diagnostic log shows M30's internal rewind firing 125ms after cycle start with no macro involvement at all — the macro is simply never called.
The johnny5 profile folder does not contain a Modules subfolder. The default Mach4Mill profile does not appear to have .mcc files either.
Doe anyone know what is preventing macro compilation and execution in this profile please? Is there a configuration step I am missing when setting up a new profile from scratch via the PoKeys wizard?
Thanks very much in advance for reading, and giving this some thought.
Re: Macros not compiling or executing - no .mcc files created on startup
« Reply #1 on: March 08, 2026, 10:02:32 PM »
Hi,
I'm no expert in Mach4 Lua coding but I've never written 'luafunction m6()', but rather just 'function m6()'.

function m100()               rather than:

luafunction m100()


Second thing I'd try is NOT use m6. m6 is reserved for tool change and in all probability Mach4 already has some rudimentary m6() code built-in. All you are doing is overwriting it.

May I suggest try the same test code, but call it m(100). I follow the old Mach3 rule, all user written scripts should be m100 or higher.
If you write your own m6 for instance then YOU MUST ASSUME RESPONSIBILITY for ALL the required functionality of an m6. If there is something that Mach expects or requires from
an m6 and you overwrite the supplied m6 then your code must include it.

My guess is that you are using chatGPT or similar to code Lua.......good luck, you get good looking code, just that it does not work! There's no substitute for rolling up your sleeves and learning this stuff
for yourself. I cannot ever see a time where AI is going to mean that humans do not have to learn. Learning is a fundamental human trait.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Macros not compiling or executing - no .mcc files created on startup
« Reply #2 on: March 09, 2026, 02:24:13 AM »
Hi Craig

Thanks very much for takig the time to reply.  I have learned alot from reading your posts on this forum, so thanks for that too.  I'm now thinking that the issue might be that the profile hasnt been properly generated by the Pokeys plugin.  My macros folder for Johnny 5 is empty but a profile that I made years ago for some preliminary testing (this DIY build has been on and off again for years) has an m6.mcc, m6.mcs and mclua.mcc in it's macros folder, which seems like it could be significant.  I might try and make a new profile and see what happens. I will also do as you suggest although I think I did already try making an m100 and nothing happened with that either. I dont want to edit m6 I just want mach to run it, which it currently wont. You are absolutely correct about AI.  I was using Claude but quickly found it's limits. 
Thanks again for your help 
Re: Macros not compiling or executing - no .mcc files created on startup
« Reply #3 on: March 11, 2026, 10:58:22 AM »
Here is a example Mcode I would reccomend starting with that has error checking. Make sure that your file name is also the name of your mcode.

Example with parameters:

File name: m100.mcs
Code: [Select]
function m100()-- It uses pcall to call the _m100 function in protected mode, which means that any errors that occur during the execution of _m100 will be caught, preventing the script from crashing.
local is_ok, msg = pcall(_m100)
if is_ok ~= true then
wx.wxMessageBox(tostring(msg))
end
end

function _m100()
--Your Code contents here
end

if (mc.mcInEditor() == 1) then
m100()
end

Here is a real example I have used in the past:

This code Swapped motors and ran and then ran a M3 code

Code: [Select]
function m23(hParam)-- It uses pcall to call the _m23 function in protected mode, which means that any errors that occur during the execution of _m23 will be caught, preventing the script from crashing.
local is_ok, msg = pcall(_m23, hParam)
if is_ok ~= true then
wx.wxMessageBox(tostring(msg))
end
end

function _m23(hParam)
local inst = mc.mcGetInstance()
local motor_5 = 5 --Setting your motor_5 to index 5 for readability
local axis_A = 3 --Setting your axis_A to index 3 for readability
local axis_OB1 = 6 --Setting your axis_OB1 to index 6 for readability
local getAxis = mc.mcMotorGetAxis(inst, motor_5)
local varS = 0 -- Setting S as your Spindle speed

if (getAxis == 3) then
mc.mcAxisUnmapMotor(inst, axis_A, motor_5) -- Changing these will not change the default settings.. this will just change for the duration of the session.
mc.mcAxisMapMotor(inst, axis_OB1, motor_5) -- Changing these will not change the default settings.. this will just change for the duration of the session.
mc.mcMotionSync(inst) --It's a good idea to sync when you change this information.
end

if (hParam ~= nil) then
varS = mc.mcCntlGetLocalVar(inst, hParam, mc.SV_S) -- This passes S into your varS value
end
gCode= ''
gCode= gCode..string.format("M3 S%0.f\n", varS)--This runs the gcode M3 S####
mc.mcCntlGcodeExecuteWait(inst, gCode)
end
if (mc.mcInEditor() == 1) then
m23()
end

I recommend looking at this documentation as this has the basic M Codes that are typically used.

https://support.machmotion.com/books/software/page/mach4-g-code-and-m-code-reference
Thanks,

Paul