I checked it again. it was my fault..
without the last added command line "(debug, tool number at this point is #<tool>)"
it works.
I didn't change N0050 T00 M6 to N0050 T01 M6 at the first trial.
so I just changed only
O200 if [#<_hal[gmoccapy.toolmeasurement]> EQ 0] to O200 if [#<_hal[gmoccapy.toolmeasurement]> EQ 0 OR #<tool> EQ 0]