Grouping curves that form multiple rectangles with overlapping corner points

Currently I am making a dynamo graph which generates beams with lines imported from CAD.

I have used the Group Curves node from the archi-lab package successfully to group curves by closed lines per beam to find the centre line for each rectangle, however when the rectangle endpoints overlap, multiple beams get grouped together (understandably).

I am trying to understand the logic to separate rectangles where some of the endpoints overlap, and rectangles where all endpoints overlap.

Please see the image below.

Case 1 is a list of 16 lines, where 3 points overlap. I would like to group the lines into 4 different groups, where the lines form a closed rectangle. The final list will contain sublists red, green, blue, black, each with their respective four lines.

Case 2 is where the all rectangles have overlapping points. I would like to group the curves in the same way as Case 1.

Ideally a routine would be able to cover case 1 and case 2, or I could filter lines depending on the case?

It would be great if you guys could point me in a direction to find a solution to this problem!

Thanks

If you place each group on a separate layer in Autocad (there are LISP routines that can automate this), you could then use BimorphNodes CurvesFromCADLayers node which automatically sorts converted curves into sub lists based on their host layer

2 Likes

Fantastic, works a charm. Thanks a lot!