Attached text to line segment

Is there a way to attach text to a line segment so if you move this segment the text also moves with it? You get set the orientation based on an object.

This could also work well for utility runs.