'  tool = GetSelectedTool()'  SetCurrentTool( tool )Sub Main()Dim Zpos As DoubleDim SpindleShift As DoubleDim MoveDist As DoubleDim ZeroSpeed As IntegerDim SpEncStart As DoubleDim SpEncFin As DoubleDim RotationCheck As DoubleDim SpindleGearShift As DoubleDim DoorStatus As IntegerDim ChangerBrake As Integer'Door interlock checkDoorStatus=IsActive(Input3)If DoorStatus = -1 ThenOldTool = getdro(24)'GetOEMDRO (1200) 'Tool In spindle DRO 1200 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 ) NewTool = GetSelectedTool()'Tool Changer Macro (Mill Type)MaxToolNum         = 10     'Max number off tools for the changerToolClearHigh      = 7.350  'Z Hieght To be clear above the tool to rotate above the toolToolChangePosition = 8.000  'Z Height to engage the tool changer GearToolClearLow       = 0.000  'Z Height to clear the tool changer on the lower sideFeed               = 250    'Feed to move at when doing the tool changeZpos       = 0.0SpindleGearShift   = -6.59   'Shift spindle for proper alignment of gearsZeroSpeed = OEMTRIG2ChangerBrake = Output3'Add code to set to absolute position mode and return to previous stateCodeSingle "G90"If NewTool = OldTool Then  Exit SubEnd IfIf NewTool < 1 Then MsgBox ("Invalid tool number") DoButton(21) Exit SubEnd IfIf NewTool > MaxToolNum Then MsgBox ("Invalid tool number") DoButton(21) Exit SubEnd If'Disable softlimits if onSoftLim = GetOEMLED(23)If (SoftLim = true) Then DoOEMButton(1029)End IfDoSpinStop() 'check to see that the spindle is stopped & activate spindle pos modeWhile(IsActive(ZeroSpeed) = false)Sleep(200)WendCodeSingle ("M13")While (Ismoving())Sleep(50)WendCodeSingle ("G01 G53 Z" & ToolClearHigh & " F" & Feed) 'move tool too the clear hright above the headWhile IsMoving()Sleep(10)WendCodeSingle ("G00 C" & SpindleGearShift)Sleep(200)CodeSingle ("G01 G53 Z" & ToolChangePosition & " F" & Feed/2) 'move tool to engage the gear of toolchangerWhile IsMoving()Sleep(10)WendActivateSignal(ChangerBrake)Sleep(200)'SpEncStart = GetOEMDRO(100) 'Get spindle encoder start countCall SpindleMoveDist(OldTool, NewTool, MoveDist)MoveDist = MoveDist + SpindleGearShiftCodesingle ("G0 C" & MoveDist) 'move tool to engage the gear of toolchangerWhile IsMoving()Sleep(10)Wend'Sleep (2500)'SpEncFin = GetOEMDRO(100) 'Get spindle encoder finish count'Check that spindle rotated proper amount'RotationCheck = Abs(Abs((SpEncFin - SpEncStart)/11.377778) - Abs(MoveDist - SpindleGearShift))'MsgBox("Difference in rotation is " & RotationCheck)'If (RotationCheck > 6.) Then' MsgBox("ERROR, Tool magazine did not rotate to proper position")' DoButton(21)' Exit Sub'End IfDeActivateSignal(ChangerBrake)Sleep(200)CodeSingle ("G01 G53 Z" & ToolClearHigh & " F" & Feed) 'move above the new tool and re home the SpindleWhile IsMoving()Sleep(10)WendRotations = Round((MoveDist / 360),0)MoveDist = Rotations * 360CodeSingle ("G0 C0") 'move Spindle to go down onto the next tool...While IsMoving()Sleep(10)WendCodeSingle ("G01 G53 Z" & ToolClearLow & " F" & Feed) 'move above the new tool and re home the SpindleWhile IsMoving()Sleep(10)WendCodeSingle ("M15")'Take the spindle out of Position ModeCall SetUserDRO (1200,NewTool)SetCurrentTool( NewTool )DoOEMButton(1029)'Soft limits OnElse MsgBox("Door must be closed to change tools") CodeSingle ("M30")End IfEnd SubSub SpindleShift(ByVal ToolNumber As Integer, ByRef Shift As Double)Select Case ToolNumber       Case Is = 1        	 Shift = 0       	        Case Is = 2         Shift = 0                Case Is = 3         Shift = 0	        Case Is = 4         Shift = 0                Case Is = 5         Shift = 0                Case Is = 6         Shift = 0                Case Is = 7         Shift = 0                Case Is = 8         Shift = 0                Case Is = 9         Shift = 0              Case Is = 10         Shift = 0         End SelectEnd SubSub SpindleMoveDist(ByVal OldTool As Integer, ByVal NewTool As Integer, ByRef MoveDist As Double)inc = 87.2727MovesPos = 0If(NewTool < OldTool)Then   NewTool = NewTool + 10End IfMovesPos = NewTool - OldToolMovesNeg  = 10 - MovesPosIf(MovesPos < MovesNeg)Then    MoveDist = inc * MovesPosElse    MoveDist = inc * -1 * MovesNegEnd If End SubMain                                               