Dimension Slab openings to grids


Imagine this scenario, you have some slabs/floors and plenty of openings for services ( different sizes, all square and rectangular) and you would like to create a script to create dimensions to each opening side from specified grids on two directions ( orientation of slabs is different and have some times their own set of grids) . I have some ideas but some extra help would make it better.