Placing linebased family around perimter of windows/door

I’m trying to create a script that can placed linebased families around the perimeter of windows and doors.

I have been looking into this script made by Konrad.

https://forum.dynamobim.com/t/placing-line-based-family/43699/3

And I can make it work for top/bottom more or less without any problems.

But when it comes to the sides, I have hit a brick wall.
As the linebased families only want to be placed horizontally.

I’m not sure how to proceed from as I guess the “FamilyInstances.ByLine” is not the right solution to get the results I want.
Have anyone tried to do something similar with success? Or help me get in the right direction on solving this?

I have attached a picture left is what I have achieved so far, right is what I want.