OK, I think this fixes it. Put this in M6End.m1s:
REM Get the length of the previous tool, stored in UserDRO 1200 by M6Start macro
OldToolLength = GetUserDRO(1200)
REM Get the length of the current tool
NewToolLength = ToolLengthOffset()
REM Figure out how much tool length changed, and in which direction
OffsetChange = NewToolLength - OldToolLength
REM Get the Z DRO value before the new tool length was applied, stored in UserDRO 1201 by M6Start macro
OldZPos = GetUserDRO(1201)
REM Correct for any moves the user made while changing the tool
CurrentZPos = GetOEMDRO(802)
ZMove = CurrentZPos - OldZPos + OffsetChange
NewZPos = OldZPos + ZMove
SetOEMDRO(802, NewZPos)
REM Get the cuurent A axis (knee) position, and apply the new tool length
OldAPos = GetOEMDRO(803)
NewAPos = OldAPos - OffsetChange
REM Move the knee to the new position
Code "G00 A" & NewAPos
REM Return the the position we were in before the toolchange
x = GetToolChangeStart( 0 )
y = GetToolChangeStart( 1 )
z = GetToolChangeStart( 2 )
a = GetToolChangeStart( 3 )
b = GetToolChangeStart( 4 )
c = GetToolChangeStart( 5 )
if(IsSafeZ() = 1) Then
SafeZ = GetSafeZ
if SafeZ > z then
GotoSafeZ()
end if
Code "G00 X" & x & " Y" & y
Code "G00 Z" & z
else
Code "G00 X" & x & " Y" & y
end if
Regards,
Ray L.