Hi Folks, I just posted an article in the gcode forum describing how I am using conditional code execution in Mach with my Tormach for complex multi-part fixturing, among other uses.
You can read the long-winded posting here:
http://www.cnczone.com/forums/showthread.php?t=94727
The abbreviated version is this:
Set a binary flag (0 or 1) depending on your condition, then multiply this flag by the intended subroutine label on the M98 line to either execute the subroutine or to execute subroutine 0, which is coded to return immediately. This is an example of an if-then clause. An if-then-else clause can be constructed by adding the flag to a base label number. If the flag is clear, the base subroutine is called, if it is set then a different subroutine label is called (base+1).
Example:
Code:
#5 = 0 (this enable flag must be 0 or 1)
M98 P[ #5 * 20 ] ( if( #5 is 1 ) then call sub 20, else nothing )
M98 P[ #5 + 21 ] ( if( #5 is 1 ) then call sub 22, else call sub 21 )
M30
O0 (do nothing subroutine)
M99
O20 (operation subroutine)
... (do stuff)
M99
O21 (flag clear subroutine)
...
M99
O22 (flag set subroutine)
...
M99