'-------------------
'Josh Haywood I'll Do It Myself XYZ Probe Macro
'To probe Z-
'https://www.youtube.com/illdoitmyself
'Note: This script is designed for metric units e.g. mm
'-------------------
Dim PlateHeight As Double, FeedCurrent, ZPosCurrent As Double

'PlateHeight = getoemdro(1001) ' Get Plate Height (Mach3 Plate height)
PlateHeight = getoemdro(1151) ' Get Plate Height (Darkscreen PlateHeight)
FeedCurrent = GetOemDRO(818) 'Get the current settings

If GetOemLed (825) <> 0 Then 'Check to see if the probe is already grounded or faulty
  Code "(Probe plate is grounded, check connection and try again)"
Else
  ' ###### Probe Z- ######-
  ZPosCurrent = GetDro(2) 'Get current position
  Code "F100" 'slow feed rate to 100 mm/min

  Code "G31 Z" & (ZPosCurrent - 25) 'probe 25mm down
  While GetOemLed (825) = 0
    Sleep(1)
  Wend

  Sleep(250) 'Wait for DRO to update

  Call SetDro (2, PlateHeight) 'Set the Dro

  Sleep(250) 'Wait for DRO to update
	
  Code "G0 Z" & (GetDro(2) + Abs(10)) & " F400" 'Move off the plate 10mm
  While IsMoving()
  Wend

  Code "(Z Axis Zeroed for PlateHeight:" & PlateHeight & ")"
  Code "F" & FeedCurrent 'Restore Feedrate
End If