If GetOemLED(16)<>0 Then 'Checks for machine coordinates
	MsgBox "Please change to working coordinates"
Else
	If GetOemLed (825) <> 0 Then       'check to see if the probe is already grounded or faulty
		MsgBox "Z-Plate is grounded, check connection and try again" 'this goes in the status bar if aplicable
	Else
		Tools
	End If
End If

Sub Tools()
	Dim CurrentFeed
	CurrentFeed = GetOemDRO(818)
	'Code "F500"
	
	' _______________________________________________________________________
	
	Dim Message
	Dim Title
	Dim Tool
	
	Message = "Enter tool number"
	Title = "Tool Z"
	Tool = GetCurrentTool() ' Mach selected Tool by default.
	'Sleep 1000
	Tool = CInt(InputBox(Message, Title, CStr(Tool), 100, 100))
	If Tool <= 0 Or Tool >255 Then
		Exit Sub
	End If
	
	SetCurrentTool Tool
	'Code "G4P2"
	'sleep 1000

	' _______________________________________________________________________
	
	Dim ZInitial
	Dim ZPlate
	Dim ToolZOffset
	Dim HeightBetweenToolAndPlate
	
	'ZInitial = GetDro(2)
	ZInitial = GetOEMDro(180)
	'Code "G4P2"
	sleep 1000

	Code "G0 G31Z" & (ZInitial - 500)' & " G4P1"
	Code "G4P1"
	'Code "G1Z" & (ZInitial - 500)
	'Exit Sub
	W'P
	'ZPlate = GetDRO(2)
	'msgbox GetOEMDro(180)
	ZPlate = GetOEMDro(180)
	'Code "G4P2"
	sleep 1000


	
	Code "F100"
	'sleep 1000
	Code "G1Z" & ZPlate+1
	W
	'ZPlate = GetDRO(2)
	ZPlate = GetOEMDro(180)
	'Code "G4P2"
	sleep 1000



	
	Code "F50"
	'sleep 1000
	'DoOEMButton(1003)
	'DoOEMButton(1000)
	'sleep 1000
	Code "G31Z" & ZPlate-2' & " G4P2"
	Code "G4P1"
	'Code "G1Z" & ZPlate-5
	W'P
	'ZPlate = GetDRO(2)
	ZPlate = GetOEMDro(180)
	'Code "G4P2"
	sleep 1000



	' _______________________________________________________________________
	
	If Tool=1 Then	' save height in Mach variable for Tool 1 only
		HeightBetweenToolAndPlate = ZInitial-ZPlate
		SetVar 1234, HeightBetweenToolAndPlate
		SetVar 1233, ZInitial
	End If
		'Sleep 1000
	
	'Code "F300"
	'sleep 1000
	'ZInitial = ZPlate + GetVar(1234)
	Code "G0 Z" & ZPlate + GetVar(1234) +1 	'ZInitial
	W
	'Code "G4 p1"
	Code "G1 Z" & ZPlate + GetVar(1234)	'ZInitial
	W
	sleep 2000
	'SetDro 2, 0
	SetDro 2, GetVar(1233)
	'Code "G4P2"
	'sleep 2000

	Code "F" & CurrentFeed 
	'sleep 1000
End Sub



Sub W()
	'Code "G4P0.1"
	'Sleep 100
	While IsMoving()
		Sleep 100
	Wend
	'Code "G4P2"
	'sleep 1000

End Sub

Sub WP()
	'While Not GetOEMLED(825)
	While Not IsActive(Digitize)
		Sleep 100
	Wend
	DoOEMButton(1003)
	DoOEMButton(1000)
	'sleep 1000
End Sub                                                                                                                                                                                                                      
                      
