Using Macros to log data during simulations

I want to log the distance between two parts (or a log entry when they come to a certain distance)

It is possible to write a macro to do it or is there a way to do it?

Cheers,

SolidworksSimulation