first Change your M6End code to:
REM The default script here moves the tool back to m6start if any movement has occured during the tool change..
REM x = GetToolChangeStart( 0 )
REM y = GetToolChangeStart( 1 )
REM z = GetToolChangeStart( 2 )
REM a = GetToolChangeStart( 3 )
REM b = GetToolChangeStart( 4 )
REM c = GetToolChangeStart( 5 )
REM if(IsSafeZ() = 1) Then
REM SafeZ = GetSafeZ()
REM if SafeZ > z then StraightTraverse x, y,SafeZ, a, b, c
REM StraightFeed x, y, z , a, b, c
REM else
REM Code"G00 X" & x & "Y" & y
REM end if
normaly you set your G54 Z Zero to the top of your workpiece, and work then with neative Z values to do the Job.
in the M6Start macro you can add code to get the Z axis to a Position where you can do your tool Change.
in M6End is only code needed if your cam does not bring back the Z-axis to a Position where it is needed after toolchange,
but your example G.code does this, so only one part of Software should o this (G-code or M6End macro), never both of them.