Connecting and trimming curves

Hi all,

The black curves that you see here have been translated inwards from the surfaces representing a “Space” object in Revit. I need to trim the corners and connect the unconnected sections of the curves to create a nice clean line which I can turn into a solid to generate a grid of points.
I am having trouble working out how to do this though…
The red line represents the final result that I am after. Can anyone help point me in the right direction for this? Thank you so much.

Try to get all perimeter lines in one polycurve and follow the below shot.

Thank you very much, this put me on the right track!