Sub ATC(CurrentToolNum)'---------------M6 Start, rutina de canvi deines tinc que intentar adaptar la que tinc i aquesta------------'''--- Variables:------NewTool = CurrentToolNum										'Tool number of the tool to change toOldTool = GetCurrentTool()										'Tool number of the tool to change from (tool in spindle)WorkX = GetToolChangeStart(0)										'X position from where the tool change was initiatedWorkY = GetToolChangeStart(1)										'Y position from where the tool change was initiated		WorkZ = GetToolChangeStart(2)										'Z position from where the tool change was initiatedMaxToolNum = 8												'Maximum number of tools, in order to check if a legal tool number is requiredToolTreverse = -75											'M.C. Height while moving from one tool pisition to another with safe heigh for avoid colisions of tools with tool holderSafeZ = -5												'Extra safe ZDrawBar = Output11											'Output Port of mach3Airblow = Output12											'Output Port of mach3----- i need to change this i use airblow and drawbar at same time and i use output12 for pneumatic tool holderXpos = 0												'X Height of each individual tool in tool holder (0 is dummy value)YPos = 0												'Y Height of each individual tool in tool holder (0 is dummy value)ZPos = 0												'Z Height of each individual tool in tool holder (0 is dummy value)YPosSlide = 570.00											'Distance from bed toolholder to start sliding the tool into holder (this number is only for test in air without danger of break something, when this script work i go to put the correct numbers)While OldTool = 0 Or OldTool > MaxToolNum								'When mach3 boots up the current tool is always number T00, so i need to change it because it because in this script tool 0 doesnt work and if the tool is more than maxtoolnum too.OldTool = Question ("Invalid tool number in Spindle! Enter: [1-" & MaxToolNum & "]")			WendIf NewTool = 0 Or NewTool > MaxToolNum Then								'Check if the requested tool is within range of the changer (from 1 to maxtoolnum)Message "Invalid tool number request ! [Tool #" & NewTool & "]"						'If no stop the programCode "M30"												'STOP program, reason is that tool length compensation is controlled in the Exit Sub												'Then exit this tool change routineEnd IfIF NewTool = OldTool Then										'If the new tool is identical to the old tool	Exit Sub											'I dont need a tool change because i have the correct tool in spindleEnd IfCode "G00 G53 Z" & SafeZ										'Goto safe traversing height. Rapid move to machine coords of SafeZ height configured in script'----Place old tool in bed holder----Call ToolPos (OldTool,XPos, Ypos, ZPos)									'Call the sub routine to get coords for old tool positionCode "G53 X" & Xpos & "Y" & YPosSlide									'Move to sliding positionCode "G53 Z" & ToolTreverse										'Move spindle to tool traversing heightWhile IsMoving()											'Wait for movement to finishSleep(100)Wend' ActivateSignal(Airblow)										'DEACTIVATED!!!! Turn on the air blow deactivated because i use airblow and opencollet in the same output (same time)Code "G53 Z" & ZPos											'Move down to place tool in the changerCode "G53 Y" & Ypos											'Slide tool into bed holderWhile IsMoving()											'wait for movement to finishSleep(100)																		WendActivateSignal(DrawBar)											'Activate the drabar and release the toolSleep(1000)												'Wait 1 second for open the drawbarCode "G53 Z" & ToolTreverse										'Move to safe tool traversind height'------- Pick up new tool from bed holder ---------Call ToolPos (NewTool,XPos, YPos, ZPos)									'Call the sub routine to get coordinates for new tool positionCode "G53 X" & Xpos & "Y" & YPos									'Move to new tool positionCode "G53 Z" & ZPos											'Down to dis-engage the toolWhile IsMoving()											'Wait for movement to finishSleep(100)WendDeActivateSignal(DrawBar)										'Deactivate the drawbar and clamp the tool' DeActivateSignal(Airblow)										'DISABLED!! Deactivate the airblowSleep(6000)												'Wait for drawbar to engage (6 seconds for the moment i need to test how many time need when all works)Code "G53 Y" & YPosSlide										'Move tool out the tool holder (sliding)Code "G53 Z" & SafeZ											'Move to Z safeSetCurrentTool(NewTool)											'Now set the new tool as current toolSleep(250)												'Wait for DRO to update'End Sub'--- Find the coordinates of the tool positions in the Bed-Tool holder ----Sub ToolPos(ByVal ToolNumber As Integer, ByRef XPos, ByRef YPos, ByRef ZPos)		'Subtoutine to find tool location coordinates	Select Case ToolNumber		Case is = 1								'If the tool number is 1 then read these XYZ positions					Xpos = 112.25					'Here specify  the Machine coords of the tool 1 position.					Ypos = 304.79					'same for all cases					Zpos = -80.00		Case is = 2					Xpos = 212.25					Ypos = 304.79					Zpos = -80.00					Case is = 3					Xpos = 312.25					Ypos = 304.79					Zpos = -80.00		Case is = 4					Xpos = 412.25					Ypos = 304.79					Zpos = -80.00		Case is = 5					Xpos = 512.25					Ypos = 304.79					Zpos = -80.00		Case is = 6					Xpos = 612.25					Ypos = 304.79					Zpos = -80.00		Case is = 7					Xpos = 711.50					Ypos = 304.79					Zpos = -80.00		Case is = 8					Xpos = 111.50					Ypos = 304.79					Zpos = -50.00						End Select	End Sub 