Hi,
there are two ways that I know of.
I use Autoleveller, a freeware program that generates a Gcode probing routine from your original Gcode file,
then probes the substrate, then corrects the original Gcode file to accommodate the substrate not being perfectly flat.
I've been using it for years making PCBs which are very sensitive to Z axis engraving/cutting height.
The other is the mcSurface wizard of Mach4. It will probe an area according to your definition and then automatically
adjust ALL z axis ordinates thereafter, on the fly, without recomposing or otherwise editing the Gcode.
Both achieve the same result. Autoleveller is a clear and transparent process that is used again and again as required. mcSurface
is more intended that the baseboard of the router be probed and thereafter all corrections happen within Machs core and not
really subject to your control. It was always intended as a 'probe once and forget' type solution whereas Autoleveller is a
'probe each workpiece and modify the Gcode to suit' solution.
Either will work.
Craig