Saturday, 31 January 2026

LinuxCNC hell - can Gemini AI help?

Oh no, not AI again?

Oh yes. Although ChatGPT got a whole load of exposure and caused a whole load of excitement last year, AI is a bit more useful than just a means of getting your homework done for you.

I've struggled to get Andy Pugh's macros to run on my LinuxCNC lathe. There's a "sim" (aka dummy demo) that implements the gmoccapy GUI with Andy's macros but to go from there to a functioning machine is a bit of a step. To get it running, you need to get all these elements set up and working correctly:

  • .INI file. Contains file paths, machine parameters etc for your specific machine, including specifying the other config files.
  • .HAL file. Provides the virtual wiring that connects the myriad external inputs and outputs, along with the RTOS-driven stepgen etc software elements that make things happen. My machine has closed loop positional control of the X and Z axes, using glass linear encoders, as well as a wireless pendant (WMPG). 
  • .UI file used by the Glade user interface. The "gmoccapy" lathe GUI is programmed in Glade by means of this .UI file.
  • Various tool tables, macros etc.
  • ...and of course, Andy's macros themselves.
I generally find that the LinuxCNC forum members try to be helpful but they are very busy developing the software as well as fielding a wide range of problem solving and development issues. I hate to say it but I feel there is also a bit of a macho mindset - perhaps you sort of need to prove yourself and make your own way to some degree before you will be fully respected there. Perhaps I'm just not asking the right questions of the right people in the right way.

Anyway, back to AI. There are some great examples showing how you can use AI's "coding agents" to help you to write surprisingly usable software code - and even debug issues.

 Andreas Speiss: 

Dave's Garage:


Networkchuck - use command line interface (CLI) rather than GUI, to interact with the "agents":

So, lets give this a go:

what changes do i need to make to a standard version of gmoccapy to implement Andy Pugh's macros?
To implement 
Andy Pugh's
 lathe macros (cycles) into a standard 
Gmoccapy setup, you must manually integrate them as an embedded tab and link the required subroutines. 
Required Configuration Changes
Modify your INI file with the following sections:
  1. Define the Subroutine Path
    In the [RS274NGC] section, point to where the macro .ngc files are stored.
    ini
    [RS274NGC]
    SUBROUTINE_PATH = /path/to/your/macros
    
    Use code with caution.
    If you keep them in your config folder, use SUBROUTINE_PATH = ..
  2. Embed the Macro Tab
    In the [DISPLAY] section, add the command to load the macro interface as a side tab.
    ini
    [DISPLAY]
    EMBED_TAB_NAME = Cycles
    EMBED_TAB_COMMAND = halcmd loadusr -Wn gladevcp gladevcp -c gladevcp -u lathehandler.py -x {XID} lathemacro.ui
    
    Use code with caution.
    • lathehandler.py and lathemacro.ui must be in your configuration folder.
    • notouch=1: Add this flag to the command if you want to use a physical keyboard for entry.
    • norun=1: Use this to hide the on-screen "Run" button if you prefer using a physical Cycle Start button.
  3. Gmoccapy Specific Macro Buttons (Optional)
    If you want quick-access buttons in the Gmoccapy MDI list, add a [MACROS] section.
    ini
    [MACROS]
    MACRO = name_of_macro_file
    
    Use code with caution.
    Gmoccapy supports up to 16 macros in this list. 
Essential Files
Ensure the following files from Andy Pugh's LatheMacros GitHub are copied into your machine's configuration directory: 
  • lathehandler.py (Python logic)
  • lathemacro.ui (GladeVCP interface)
  • All associated .ngc subroutine files (e.g., facing.ngcturning.ngc). 
Pro-tip: If you are using LinuxCNC 2.9+, be aware of potential GTK3/Python3 compatibility issues that may require updates to the .ui or .py files. 
Would you like the exact file path for the simulation demo to test these macros before editing your main config?
AI responses may include mistakes. Learn more
  • andypugh/LatheMacros: Lathe Macros for LinuxCNC - GitHub
    28 Dec 2024 — This folder contains a number of simulated lathe configs. the "lathemacro" config offers a number of simple macros to perform the ...
    GitHub
  • Gmoccapy Macros - LinuxCNC Forum
    18 Aug 2021 — there is a known issue in 2.9 / master related to Python3 and/or GTK3 which I have not been able to get to the bottom of.
    LinuxCNC Forum
  • GMOCCAPY - LinuxCNC
    15 Dec 2025 — This sets the path to search for macros and other subroutines. Configuration of Five Macros ngc" extension (case sensitive).
    LinuxCNC
Show all
yes
To test Andy Pugh's lathe macros in a safe simulation environment before editing your live configuration, you can use the built-in demo included with LinuxCNC.
Simulation Demo Path
You can find and launch the demo configuration at:
sim/gmoccapy/lathe_configs/lathe_macros.ini. 
How to Run the Demo
  1. Open your terminal.
  2. Type linuxcnc to open the configuration selector.
  3. Navigate to Sample Configurations > sim > gmoccapy > lathe_configs.
  4. Select lathe_macros.ini and click OK. 
Troubleshooting the Demo
  • Version Issues: This demo is verified to work in LinuxCNC 2.8. If you are on 2.9 or later, there is a known issue where the interface may fail to load due to Python 3 / GTK3 compatibility changes.
  • Missing Images: In newer versions, the graphical background (SVG) may not render correctly unless you update the lathehandler.py script.
  • Missing Files: If you are building a custom config from scratch, the required simulation files are located in the macros folder within the GMOCCAPY sim folder. 
Would you like the terminal command to specifically launch this simulation directly without using the configuration picker?
Andy Pugh changed lathemacro.ui in the currebt version so that the play button became greyed out. What changes need to be made to bring it back?
The play button in 
Andy Pugh
's Gmoccapy LatheMacros interface is greyed out when the configuration is set up to use a physical cycle-start button instead of an on-screen one. To bring it back, you need to modify the 
EMBED_TAB_COMMAND line in your machine's INI file and potentially edit the lathemacro.ui file. 
INI File Modification
Locate the [DISPLAY] section in your configuration's .ini file and change the EMBED_TAB_COMMAND line. The option that hides the button is norun=1. To make the button appear and be functional, you need to remove this option or explicitly set it to norun=0. 
  • Original (Button Hidden):
    ini
    EMBED_TAB_COMMAND = halcmd loadusr -Wn gladevcp gladevcp -c gladevcp -u lathehandler.py -x {XID} lathemacro.ui
    
    Use code with caution.
    The norun=1 may be implied or explicitly present in the command line options. If present, remove it.
  • Modified (Button Visible):
    Ensure the command does not contain norun=1. The GitHub documentation for the macros suggests the following syntax to explicitly keep it visible:
    ini
    EMBED_TAB_COMMAND = halcmd loadusr -Wn gladevcp gladevcp -c gladevcp -U notouch=1 -U norun=0 -u lathehandler.py -x {XID} lathemacro.ui
    
    Use code with caution.
    The -U norun=0 parameter ensures the action button remains visible. 
UI File Modification (Optional) 
If changing the INI file parameter does not work, you may need to manually edit the lathemacro.ui file directly using a text editor. 
  1. Open the lathemacro.ui file in a text editor.
  2. Search for the string related to the "Action" or "Play" button.
  3. Ensure the visibility attribute for the button is set to True (or similar, depending on the GTK version used). The buttons are still in the file and can be made visible this way. 
After making these changes and restarting LinuxCNC, the play button should be visible and clickable, provided the machine is homed and the subroutine paths are correctly set. 
AI responses may include mistakes. Learn more
  • andypugh/LatheMacros: Lathe Macros for LinuxCNC - GitHub
    28 Dec 2024 — The GUI that controls the macros can be viewed by clicking the "Cycles" tab top left of the graphical preview window.
    GitHub
  • Lathe Macros - Page 16 - LinuxCNC Forum
    18 May 2013 — The "Play" buttons are still there, and can be made visible by editing the . ui file. You might need to change the upper limits of...
    LinuxCNC Forum
  • Lathe Macros - Page 25 - LinuxCNC Forum
    18 May 2013 — There are two load-time options to control the tab behaviour: 1) norun will hide the action button, use this if you want to use on...
    LinuxCNC Forum
Show all
Which lines in lathemacro.ui need to be modified? There are many instances of "action".
In the newer versions of 
lathemacro.ui, the "Play" buttons are intentionally hidden (or "greyed out") to encourage the use of physical cycle-start buttons. You can restore them by editing the .ui file with a text editor. 
Key Modifications in lathemacro.ui
The "Play" buttons are technically defined as GtkEventBox or GtkButton elements that contain an "Action" signal. To make them visible again: 
  1. Search for "Action" and "Visible": Open the .ui file and search for the string Action to find the button definitions for each cycle (facing, turning, etc.).
  2. Change Visibility Attributes: Look for the <property name="visible"> tag associated with these buttons. In newer versions, this property may be set to False or the entire button widget may be commented out. Change it to:
    xml
    <property name="visible">True</property>
    
    Use code with caution.
  3. Identify Specific Widgets: While there are many "action" instances, look for the ones nested inside the tabs1 notebook. Each cycle has its own action button named after the tab (e.g., Facing.actionTurning.action). 
Important INI Override
Before editing the UI file, ensure your INI file isn't overriding the visibility. If your EMBED_TAB_COMMAND contains -U norun=1, the buttons will remain hidden regardless of the UI file settings. Ensure it is set as follows: 
ini
EMBED_TAB_COMMAND = halcmd loadusr -Wn gladevcp gladevcp -c gladevcp -U norun=0 -u lathehandler.py -x {XID} lathemacro.ui
Use code with caution.
Pro-Tip: Avoid Glade Editor
It is strongly recommended to use a plain text editor (like Gedit, Mousepad, or VS Code) to make these changes. Opening the file in the Glade visual editor can often break the custom formatting or CSS styling Andy Pugh used for the GTKOverlay. 
Do you want me to help you find the exact line numbers in the current GitHub version of the file?
AI responses may include mistakes. Learn more
  • andypugh/LatheMacros: Lathe Macros for LinuxCNC - GitHub
    28 Dec 2024 — 1) norun will hide the action button, use this if you want to use only a physical button. EMBED_TAB_COMMAND
    GitHub
  • Lathe Macros - Page 16 - Index - LinuxCNC
    18 May 2013 — The "Play" buttons are still there, and can be made visible by editing the . ui file (probably with a text-editor rather than risk...
    162.243.45.186
  • Lathe Macros - Page 16 - LinuxCNC Forum
    18 May 2013 — The "Play" buttons are still there, and can be made visible by editing the . ui file (probably with a text-editor rather than risk...
    LinuxCNC Forum
Show all
yes
In recent versions of 
lathemacro.ui, "Play" buttons (referred to as Action buttons) are replicated for each tab and are intentionally set to be invisible by default. To make them visible, users must edit lathemacro.ui to change the <property name="visible"> tag from False to True for each relevant Action object and potentially ensure the parent EventBox container is also visible. Additionally, the INI file must use -U norun=0 in the EMBED_TAB_COMMAND. Read more about Lathe Macros at the LinuxCNC Forum. 
AI responses may include mistakes. Learn more
  • andypugh/LatheMacros: Lathe Macros for LinuxCNC - GitHub
    28 Dec 2024 — 1) norun will hide the action button, 2) notouch will allow keyboard editing of the spinboxes.
    GitHub
  • Lathe Macros - Page 40 - LinuxCNC Forum
    15 Mar 2023 — If the button properties are "Visible" and the frame it is in is "Visible" then it should be visible. you could try changing the b...
    LinuxCNC Forum
  • Lathe Macros - Page 16 - LinuxCNC Forum
    18 May 2013 — The "Play" buttons are still there, and can be made visible by editing the . ui file. You might need to change the upper limits of...
    LinuxCNC Forum
Show all
what are the exact line numbers in the current GitHub version of the find the exact line numbers in the current GitHub version of the lathemacro.ui file
In the current version of Andy Pugh's 
lathemacro.ui file on GitHub, the "Play" buttons (Action buttons) are duplicated across different tabs (Facing, Turning, etc.) and are set to invisible by default. 
Because the file is updated periodically, exact line numbers can shift slightly, but you can find the specific targets by searching for the string .action in a text editor. 
Target Line Blocks (Approximate)
Look for these specific widget definitions and change <property name="visible">False</property> to True:
  • Facing Action Button: Search for Facing.action. The visibility property is typically located around Line 1770.
  • Turning Action Button: Search for Turning.action. The visibility property is typically located around Line 3330.
  • Boring Action Button: Search for Boring.action. The visibility property is typically located around Line 4890.
  • Threading Action Button: Search for Threading.action. The visibility property is typically located around Line 7240. 
Critical Required Step
Even if you edit the .ui file, the buttons will remain hidden if your INI file is configured with the norun=1 flag. You must update your EMBED_TAB_COMMAND in the [DISPLAY] section: 
  • Change this: -U norun=1 (or if it is missing)
  • To this: -U norun=0 
Warning: Avoid opening this file in the Glade Layout Editor. It uses a complex GtkOverlay system and manual XML positioning that Glade can break. Stick to a plain text editor like Gedit or Mousepad. 
Would you like me to provide a Linux terminal command (using sed) that will automatically flip all these "False" visibility tags to "True" for you
(I can't edit the copied and pasted dialogues once they are in Blogger - but here's a second dialogue. At this point, I'd run the Linux command to modify lathemacro.ui and it appeared to worked as intended).

I was almost there but now, when I pressed the "play" button in the macros window, I got the following error message on the command line:
It says "emc/task/emctask.cc 68: interp_error: File not open"
The error 
"interp_error: File not open" usually indicates that LinuxCNC is attempting to execute a macro but cannot find the associated .ngc (G-code) files or the parameter file. This often happens because the macro files are not in the expected search path. 
To fix this and restore the button functionality, ensure the following:
  1. Move Macro Files: Place all LatheMacro files (lathemacro.uilathehandler.py, and all .ngc files) directly into your main machine configuration folder (e.g., ~/linuxcnc/configs/your_machine/) rather than a subfolder.
  2. Update SUBROUTINE_PATH: Ensure your INI file includes the current directory in the search path so it can find the macro subroutines.
    • In the [RS274NGC] section of your .ini file, add or update:
      SUBROUTINE_PATH = .
      (The dot indicates the current config folder).
  3. Check for Parameter File: Verify that your INI has a valid parameter file entry, as missing this can trigger "File not open" errors during macro execution:
    • [RS274NGC] PARAMETER_FILE = linuxcnc.var
  4. Confirm Machine State: The "Play" button in Gmoccapy will remain greyed out—even if visibility is set to True—if the machine is not Homed or if it is not currently in MDI mode. 
Direct Command to fix the UI (if you haven't already):
If you still need to force the button's visibility in the XML:
bash
sed -i '/id="Action"/,/<\/object>/ s/False/True/g' lathemacro.ui
Use code with caution.
Does your INI file currently have the SUBROUTINE_PATH = . line in the [RS274NGC] section? 
AI responses may include mistakes. Learn more
  • Macros. File not open - LinuxCNC Forum
    21 Jan 2025 — I solved the issue by moving the files to the root of the machine configuration folder.
    LinuxCNC Forum
  • Touch off don`t work "file not open" - LinuxCNC Forum
    24 Jul 2025 — So, in this case the error seems to be caused by not finding the PARAMETER_FILE. OP: does that entry appear in your INI? And does ...
    LinuxCNC Forum
  • Lathe Macros - Page 29 - LinuxCNC Forum
    14 Oct 2022 — Create a simulated machine using the lathe_macros.ini. Launch simulated machine and check for errors. Run machine using lathe_macr...
    LinuxCNC Forum
Show all
yes
If 
SUBROUTINE_PATH = . is already there and the file is fixed but you're getting "File not open," it means LinuxCNC can't find the .ngc files associated with the buttons. The "Play" button stays greyed out because the underlying G-code routine it's trying to "play" is missing or unreadable.
To fix this, check these two specific things:
1. Copy the NGC files
The lathemacro.ui is just the "skin." The logic lives in the .ngc files. You must copy all files ending in .ngc from the LatheMacros GitHub into your configuration folder.
  • Run this to check if they are there:
    bash
    ls ~/linuxcnc/configs/YOUR_MACHINE_NAME/*.ngc
    
    Use code with caution.
    If you don't see facing.ngctaper.ngc, etc., the button will never enable.
2. Check the INI [DISPLAY] section
Gmoccapy needs to know exactly where to look for these files to "prime" the play button. Ensure these lines are in your [DISPLAY] section:
ini
LATHE = 1
# This path must point to where the .ngc files are
PROGRAM_PREFIX = ~/linuxcnc/nc_files 
Use code with caution.
The "Secret" reason it stays grey
If the files are present, the button stays greyed out until:
  1. A Macro is selected: You must click one of the side icons (like Facing or Tapering) first.
  2. Values are entered: If the fields are empty or contain invalid data, the "Play" button remains disabled to prevent a crash.
  3. Homed: You must home all axes.
If you've checked these steps and the "Play" button is still greyed out, there might be other issues with your configuration or installation. Some users have reported needing to adjust permissions for the .ngc files or ensuring that LinuxCNC itself is correctly installed and configured for their specific hardware.
I corrected the path by spelling it out in the .INI file and this simply left a "no Tool 1 found" error. The tool.tbl file listed Tool 0, Tool 4, Tool 6 etc - but not the Tool 1 it expected. I then edited the tool table by changing T0 to T1 and finally, the spindle started up. I e-stopped the machine at this point but hey, I've finally got Andy Pugh's macros running.


So, not a bad experience. Gemini actually went away and found Andy's Github site, opened the files and also worked out how they worked. And how to modify them to reinstate the hidden play button.

We'll call that a win.

No comments:

Post a Comment

LinuxCNC hell - can Gemini AI help?

Oh no, not AI again? Oh yes. Although ChatGPT got a whole load of exposure and caused a whole load of excitement last year, AI is a bit more...