Not being a computer myself, I cannot read the code just with my eyes... I would need to step through in the debugger.
I am pretty sure that the door and window openings can be included in the dimension strip as well, either by raytracing or geometric analysis of the faces of the wall solid with holes.
Would you like to provide a minimal reproducible sample case with a simple minimal model, maybe of a wall with a couple of openings and other features of interest, for people to look, see whether they can solve the complete dimensioning challenge, bite their teeth out on?
Cheers,
Jeremy