How to cut curve based on floor area

I’ve created a script that creates a line based detail item based on the curves of the contour of rooms:

So far so good! :slight_smile:

Now I want to divide those curves based on the floors that are beneath the room and I also want to divide them where there are openings of doors.
So the line that’s indicated in the picture above should be in fact 4 lines:

The goal of my script is to place (or calculate the length of the) different types of skirting boards based on the floor type beneath the room.

Hi, here is something that seems to work and can definitely be improved: