Tools

Sub Tools()
	Dim CurrentFeed
	CurrentFeed = GetOemDRO(818)
	Code "F300"
	' _______________________________________________________________________
	
	Dim Message
	Dim Title
	Dim Tool
	
	Message = "Enter tool number"
	Title = "Tool Z"
	Tool = GetCurrentTool() ' Mach selected Tool by default.
	Tool = CInt(InputBox(Message, Title, CStr(Tool), 100, 100))
	If Tool <= 0 Or Tool >255 Then
		Exit Sub
	End If
	
	'Call SetOEMDRO (824,MyValue) 'set number of tool
	SetCurrentTool Tool
	' _______________________________________________________________________
	
	Dim ZDetailZero
	Dim ZPlate
	Dim ToolZOffset
	Dim HeightBetweenToolAndPlate
	
	ZDetailZero = GetDro(2)
	'ZOriginal = GetOEMDro(192)	'G 28 Home Location Z
	
	'MsgBox ZOriginal
	
	'DoOEMButton(1024)	'	goto zero Z in machine coords
	'DoOEMButton(1022)	'	goto zero X in machine coords
	'DoOEMButton(1023)	'	goto zero Y in machine coords
	
	'Code "G91 G28 Z0"	'	goto zero Z
	'Code "G28 X0 Y0"	'	goto zero XY
	'W
	
	Code "G31Z" & (ZDetailZero - 500)
	W
	ZPlate = GetDRO(2)
	Sleep 1000
	
	Code "F100"
	Code "G1Z" & ZPlate+1
	W
	ZPlate = GetDRO(2)
	Sleep 1000
	
	Code "F50"
	Code "G31Z" & ZPlate-2
	W
	ZPlate = GetDRO(2)
	
	HeightBetweenToolAndPlate = ZDetailZero-ZPlate
	
	' _______________________________________________________________________
	
	If Tool=1 Then	' save height in Mach variable for Tool 1 only
		SetVar 1234, HeightBetweenToolAndPlate
		SetOEMDRO 42, 0 ' Offset is always 0 for Tool 1
	Else		' compare tool N with tool 1 and set the difference as tool offset
		ToolZOffset = GetVar(1234) - HeightBetweenToolAndPlate
		SetOEMDRO 42, ToolZOffset
	End If
	
	Code "F" & CurrentFeed 
End Sub



Sub W()
	While IsMoving()
		'Sleep 100
	Wend
	Sleep 1000
End Sub

                                                          
