Macros for 3D probing

Many thanks both - think that I am there now. Started with probing pins which I use for setups - X portion below which should work. Obviously need to repeat for Y. Lots of M0’s at the moment, as, well you know…

M0;Ensure that the probe is connected
M0;Jog the tool above the pin to probe
G10 L20 P1 X0 Y0 Z0						; Set zero point above pin
M0;Probe to left of pin?
G0 G90 X-10								; Move to left of pin
G0 G90 Z-15								; Drop down to probe position
G91 G21									; Incremental Mode. Use mm
G38.2 X50 F150							; Probe towards workpiece until touched - up to X50 max @ F150
G91 G0 X-4								; Move back 4mm from touched position
G38.2 X50 F75							; Probe towards workpiece until touched - up to X50 max @ F75
;G4 P0.3									; Wait

$#										; Get latest parameters
%wait

%PROBE_X1=params.PRB.x					; get X position from probe
([PROBE_X1])							; Print to console
G0 G90 Z0								; Move back to safe height
G0 X0									; Recentre bit
M0;Probe right of pin?
G0 G90 X10								; Move to right of pin
G0 G90 Z-15								; Drop to probe height
G91 G21									; Incremental Mode. Use mm
G38.2 X-50 F150							; Probe towards workpiece until touched - up to X50 max @ F150
G91 G0 X4								; Move back 4mm from touched position
G38.2 X-50 F75							; Probe towards workpiece until touched - up to X50 max @ F75
;G4 P0.3									; Wait

$#										; Get latest parameters
%wait
%PROBE_X2=params.PRB.x					; get X position from probe
([PROBE_X2])							; Print to console

%newX = ([PROBE_X1]+[PROBE_X2])/2

G10 L2 P0 X[newX]						; Reset X zero (should be directly over pin)
G90 G0 Z0								; Return to safe height

Thanks all again for the help.