Vmax549,
I do not think there is anything wrong with the code segment, but here it is. I set my router bits up with collars, so, once they are set, they do not change. I can remove them from the router, put them back in, and as long as they collar contacts the collet, all is good. So, you will see in my code segment that I initialize the machine before calibrating the height of the bit. In other words, it is intended to be run as a separate program, not as a subroutine within the program.
I did some additional testing on the when it saves. This is what I found.
Run the snippet ... Exit the program ... tool offsets are not saved
Run the snippet ... Run Config/Save Settings ... Exit the program ... tool offsets are not save
Run the snippet ... Go into the Tool Table ... Select APPLY ... Exit the program ... TOOL OFFSETS ARE SAVED
Apparently, although the tool table is updated within Mach by the snippet, they will not be written to disk unless I hit APPLY within the tool table.