ok, here the corrected version:
Sub Main
cutheight = 20
cutpos = 0
ZProbePos = 0
    Code "G31 Z-200 F150" 'do the probing 
    While IsMoving() 'wait for finish 
    Wend           
    
    'get the position where we hit the probe
    ZProbePos = GetVar(2002)    
    cutpos = ZProbePos - cutheight
    'go to cutting heigt
    code "G1 Z" + CStr(cutpos) + "F100"
    'set new z-Pos
    SetDRO(2,cutheight) 
End Sub
but the logic  sequence would be to do a ref all first,
and the run the script, because the ref Z will "destroy"
your probe height.
Thomas