'Macro to auto offset tool after tool change'with a tool setter probe, Written by R.Mannby 2006'CONSTANTSX_ProbePos = 7.50	'Machine cord. where tool setter is position Y_ProbePos = 17.18Z_ProbePos = -45Zmove = 20		'Distans to probe at Z_ProbePosSLOW = 20		'Slow feed rate at probingFAST = 500		'Fast feed rate at probingXpos = GetDRO(0) 'Get the X and Y positionYpos = GetDRO(1)Tool = GetDRO(24)Zoffset = GetVar(1000)If tool= 0 Then	Response = MsgBox ("Did you zero off the part first?",4,"Set up offset?")	If (Response = 6) Then ' pressed Yes	Code "G53 G00 Z-.1" 'Move the tool all the way up	Code "G53 G00 X" & X_ProbePos & "Y" & Y_ProbePos 'Move to the probe position	Code "G53 G00 Z" & Z_ProbePos 	While IsMoving()	Wend	Zpos = GetDRO(2)	'Start probing tool0	Code "G31 Z" & Zpos - Zmove & "F" & FAST 'Probe down FAST feed rate	While IsMoving()	Wend	Zpos = GetVar(2002) 'Probe result for Z	Code "G00 Z" & Zpos + 1.5' Move to the point where the probe hit + 0.5mm	While IsMoving()	Wend	Zpos = GetDRO(2)	'Start probing tool0	Code "G31 Z" & Zpos - 2 & "F" & SLOW 'Probe down SLOW feed rate	While IsMoving()	Wend	Zpos = GetVar(2002) 'Probe result for Z			Call SetVar(1000, Zpos)			Else	MsgBox "Set Zero on the top of the part and run again"	End IfElse		Code "G53 G00 Z-.1" 'Move the tool all the way up	Code "G53 G00 X" & X_ProbePos & "Y" & Y_ProbePos 'Move to the probe position	While IsMoving()	Wend	Response = MsgBox ("Change tool, then press ok!",0,"ToolChange") ' Stop to change tool	Code "G53 G00 Z" & Z_ProbePos 	While IsMoving()	Wend	Zpos = GetDRO(2)	OldZpos = Zpos	'Start probing tool >0	Code "G31 Z" & Zpos - Zmove & "F" & FAST 'Probe down FAST feed rate	While IsMoving()	Wend	Zpos = GetVar(2002) 'Probe result for Z	Code "G00 Z" & Zpos + 1.5' Move to the point where the probe hit + 0.5mm	While IsMoving()	Wend	'Start probing tool0	Code "G31 Z" & Zpos - 2 & "F" & SLOW 'Probe down SLOW feed rate	While IsMoving()	Wend	Zpos = GetVar(2002) 'Get the Position that the Probe hit at	Code "G01 Z" & Zpos' Move to the point where the probe hit	While Ismoving() 	Wend		If Zpos = OldZpos - Zmove Then		Response = MsgBox("Error! The tool did not hit the probe and DRO was not set",4,"Try again")		Else			SetDRO(2,Zoffset)		End If		End IfCode"G53 G00 Z-.1" 'Pick the tool up to the home switchCode"G00 X" & Xpos & "Y" & Ypos 'Move to the point where the tool change started      