I've spent a fair amount of time with Hirudin's Speedio engraving macro and recently re-wrote it for Mazak SmoothG. I'll start with a brief overview of how the macro works and then make some suggestions for how you might be able to use it to get what you want.
Hirudin included a lot of configuration/options in the macro that make it flexible but a bit difficult to understand. At its core, here's how the macro works:
- Two programs are used; I believe Hiruden uses O1080 (the macro) and O1090 (the engraving helper)
- The serial number being engraved can be specified either directly (engrave this number) or indirectly (engrave the number that this Common Variable points to).
- You also pass in an XYZ start position relative to the active coordinate system (this is where engraving will start), a desired number of digits to engrave (this will automatically zero-pad the serial number so that 4 becomes 00004 or whatever you want), and an XYZ stepover amount per-digit (it's possible for your engraving helper to specify a custom stepover for variable-width fonts, but let's ignore that for now).
- The macro will then "loop" through the serial number, calling into the engraving helper (explained in a minute) to engrave each digit. How it loops through the serial number is easiest to explain with a bit of pseudocode:
Code:
serial = 12345
serial / 10000 = 1.2345
integer(1.2345) = 1
engrave 1
serial = serial - 1*10000
# serial is now 2345
serial / 1000 = 2.345
integer(2.345) = 2
engrave 2
serial = serial - 2*1000
...etc.
- Instead of doing this manually, the macro tracks the current power of 10/etc. and loops through until you get to 0 (or something of that nature).
- For each digit, the macro shifts the local coordinate system using G52 in order to handle character spacing.
- The engraving helper is a macro itself that takes a single argument A to determine what digit should be engraved. A10000 will run any setup that needs to happen (tool change/etc.), A80000 engraves 0, A80001 engraves 1, A80002 engraves 2, etc.
- Each digit is called individually, so the engraving helper returns control back to the macro with M99 after engraving a single digit using the current coordinate system zero.
- The benefit of this system is that you can have multiple engraving helper programs that are differently sized, use different fonts, different tools, etc. I generate the engraving helper in CAM and then modify the program by hand to run the right part of the program based on how its called. Hirudin goes into this in the video, I believe.
It's very possible to adapt this system to support revision characters by mapping them to a digit. A could be 1, B 2, C 3, etc. Hiruden uses
N8000x in the engraving helper to refer to digits and you could just extend that such that
N810xx refers to characters. Pick some unused argument to the macro, let's say M/#13, and modify the macro with something like this after it loops through the serial number:
Code:
(Original macro loop)
WHILE [ ... ] DO 1
...
END 1
(Added code)
IF [#13 EQ #0] GOTO 99991
G52 X#4 Y#5 Z#6
G65 P#1 A[81000 + #13]
GOTO 99991
To engrave the date, we can use the same power-of-10 "trick" to convert the date system variable to the format you want (
#3011, the current date with format YYYYMMDD):
Code:
#1 = #3011 (Current date, 20220114)
(Get the year)
#2 = FIX[#1 / 10000]
#1 = #1 - [#2 * 10000]
#2 = #2 - [[FIX[#2 / 100] * 100] (Convert 4-digit year to last-2-digit year)
(Get the month)
#3 = FIX[#1 / 100]
#1 = #1 - [#3 * 100]
(Get the day)
#4 = #1 (all the remains)
(Convert to DDMMYY)
#5 = [#4 * 10000] + [#3 * 100] + #2
After all this, #5 now contains a number that you could pass to the engraving macro in order to engrave the date.
Okay, that was quite a lot, so I'll leave it at that for now. Please know that everything above would need to be tested extensively/etc. before running. Please don't crash your machine trying to run my bad pseudocode.
