Join Lines Close to Each Other

Hi everyone,
I’m a little stuck in the development of one of my scripts and was hoping someone might have a thought. I have a script where I’m extracting the exterior face of the walls. I want to then join walls that are next to each other (or in corners). Ultimately I want to extrude to find the true area of the wall (given Revit’s built-in wall area calculation is a little off).

I’ve been trying to use the Springs.LineLoop.Merge node to join walls together and it works great when all the walls in a list (or in my case a level of a building) are touching each other. When all the walls in a list do not touch each other the node doesn’t join any of the walls.

I was trying to figure out a way to make it work and I thought if I could group the lines in proximity to each other together (within a tolerance) then run through the list that could work, but given the list order of walls (and start and end points) is completely random and related to the order and direction drawn, that task seems more complex in reality than theory.

I have a little test project (attached) where I split the walls on the 2nd floor. I got as far as removing the walls that are in the middle of walls, but as you can see when I run it through the Springs node it doesn’t join the lines on the 2nd floor.

Model the script is being run against:

line merge test2.dyn (81.6 KB)

Any thoughts?

I found this post:

and it seemed promising. My thoughts were I could take this to determine lines (by start/end points) that were within a certain distance, but the prospect of that seems a little daunting/complex.