Sub Main()
OldTool = GetOEMDRO (1200) 'Tool In spindle DRO You must add this to your settings screen
x = GetToolChangeStart( 0 )
y = GetToolChangeStart( 1 ) 
z = GetToolChangeStart( 2 ) 
a = GetToolChangeStart( 3 ) 
b = GetToolChangeStart( 4 ) 
c = GetToolChangeStart( 5 ) 
tool = GetSelectedTool()
NewTool = tool
'Tool Changer Macro (Bed Type)
MaxToolNum = 6      'Max number off tools for the changer
Select Case ToolNumber
  Case Is = 1
  Tooldown = -3.425
  Case Is = 2
  Tooldown = -3.500
  Case Is = 3
  Tooldown = -3.573
  Case Is = 4
  Tooldown = -3.425
  Case Is = 5
 Tooldown = -3.500
  Case Is = 6
 Tooldown = -3.573
 End Select
ToolUp     = 0.0    'Z Hieght to Rapid from tool to tool
If NewTool = OldTool Then 
	Exit Sub
End If
While NewTool > MaxToolNum
NewTool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend
Code "G00 G53 Z" & ToolUp
While IsMoving()
Wend
Call MovePos(OldTool)
While IsMoving()
Wend
Code "G53 Z" & ToolDown
Code "G4 P.75"
While IsMoving()
Wend
If OldTool = 1 then
   Call One
If OldTool = 2 then
   Call One
If OldTool = 3 then
   Call One
If OldTool = 4 then
   Call Two
If OldTool = 5 then
   Call Two
If OldTool = 6 then
   Call Two
End If
Call MovePos(NewTool)
While IsMoving()
Wend
If NewTool = 1 then
   Call Three
If NewTool = 2 then
   Call Three
If NewTool = 3 then
   Call Three
If NewTool = 4 then
   Call Four
If NewTool = 5 then
   Call Four
If NewTool = 6 then
   Call Four
End If
Call SetUserDRO (1200,NewTool)
SetCurrentTool( NewTool )
Code "G00 Y"  & y 'Move back to where the tool change was prompted
End Sub


Sub MovePos(ByVal ToolNumber As Integer)

Select Case ToolNumber
        Case Is = 1
         YPos = 14.594
       Case Is = 2
         YPos = 9.669
       Case Is = 3
         YPos = 4.676
       Case Is = 4
         YPos = 14.594
       Case Is = 5
         YPos = 9.669
       Case Is = 6
         YPos = 4.676
   
End Select

Code "G53 Y" & YPos
End Sub

Sub One
 Activate (Output12)
 Sleep 1500
 Activate (Output16)
 Sleep 1500
 code "G53 Z" & Toolup
 DeActivate(Output12)
 Activate(Output13)
 Sleep 1500
 DeActivate(Output13)
 DeActvate(Output16)
 Sleep 1500
End Sub

Sub Two
 Activate (Output14)
 Sleep 1500
 Activate (Output16)
 Sleep 1500
 code "G53 Z" & Toolup
 DeActivate(Output14)
 Activate(Output15)
 Sleep 1500
 DeActivate(Output15)
 DeActvate(Output16)
 Sleep 1500
End Sub


Sub Three
 Activate(Output12)
 Activate(Output16)
 Sleep 1500
 Code "g53 z" & ToolDown
 DeActivate(Output16)
 Sleep 1500
 DeActivate(Output12)
 Actvate(Output13)
 Sleep 1500
 DeActivate(Output13)
End Sub

Sub Four
 Activate(output14)
 Activate(output16)
 Sleep 1500
 Code "g53 z" & ToolDown
 DeActivate(Output16)
 Sleep 1500
 DeActivate(Output14)
 Actvate(Output15)
 Sleep 1500
 DeActivate(Output15)
End Sub   