'****SETS Z ZERO OFF BILLET MATERIAL*******CODE "G40" CODE "G80"WorkOffset = 46CurrentFixture = GetOemDro(46) ' Get Fixture Number (eg:1 = G54)CurrentFeed = GetOemDRO(818) 'Get the current feedrate.'PlateThickness = 3.0 + GetUserDRO(1151) 'Set touch plate thickness here and it will 'add the material thickness from the onscreen DROPlateThickness = 1.65If GetOemLed (825)=0 Then    'If Probe is not active CurrentWorkOffset = GetOemDro(WorkOffset)    'Get current Work offsetSelect case CurrentWorkOffsetcase =1CurrentWoffset = "G54"case=2CurrentWoffset = "G55"case=3CurrentWoffset = "G56"case=4CurrentWoffset = "G57"case=5CurrentWoffset = "G58"case = 6CurrentWoffset = "G59"End SelectCode "G54" 'Set to Mach starting base offsetDoOEMButton (1010)             'Work Z ZeroCode "G4 P01"                       'Wait a bitCode "G31 Z-40 F100"             'Set probe move down distance and speed hereWhile IsMoving()Sleep 20WendZProbePos = GetVar(2002)      'Get the contact pointSleep 100Code "G1 Z" & ZProbePos       'Move back to contact pointWhile IsMoving ()Sleep 20WendCall SetOemDro (802, PlateThickness)Sleep 50Code "G4 P0.25"           'Wait a bitCode "G55"Call SetOemDro (802, PlateThickness)Sleep 50Code "G4 P0.25"           'Wait a bitCode "G56"Call SetOemDro (802, PlateThickness)Sleep 50Code "G4 P0.25"           'Wait a bitCode "G57"Call SetOemDro (802, PlateThickness)Sleep 50Code "G4 P0.25"           'Wait a bitCode "G58"Call SetOemDro (802, PlateThickness)Sleep 50Code "G4 P0.25"           'Wait a bitCode "G59"Call SetOemDro (802, PlateThickness)Sleep 50Code "G4 P0.25"           'Wait a bitCode CurrentWoffset   'Put back Work offset to the one before we started the macroCode "G4 P0.25"           'Wait a bitCode "G0 Z30"              'Change the Z retract height hereWhile Ismoving ()sleep 20WendCode "(Z axis is now zeroed)"Code "F" &CurrentFeedElseCode "(Z-Plate is grounded, check connection and try again)"Exit SubEnd If  