Auto Dimension electrical socket to nearest wall

I am looking to try find a way to do a script that would auto dimension the centre line of an electrical element to the nearest opening or wall, but not sure where to start does anyone have any ideas,

cheers