I agree with Bill, everything inside the TC should be in machine cords
I would just personally command the Z height to the correct height rather than doing a conditional.
Also at the beginning of your macro, do a machine state PUSH, then at the end do a machine state POP.
You have to activate the POP before you apply any TLO's or offsets of any nature.
Essentially it saves the state of the modals and tables and when you POP is puts them all back.
This way you don't have to worry about changing any modals or anything else within the macro, it'll all be set back to the way it was.
After the pop you can THEN change tool numbers, offsets etc.
To answer your original question, you could try checking the value of the pound var that holds the machine cord position for that axis.
The API.h is attached. You can find the var in there.