Split Duct/tray/pipe based on Space (Vertical/Horizontal)

Hi all,
Ive looked at this topic a fair bit but not sure there is a definitive solution and its getting frustrating based on my dynamo knowledge. I’m trying to split duct/tray/pipe (Vertical and horizontal) based on its intersection with its associated space. Ultimately I want to get the length of duct/tray/pipe within the space and schedule it .

I have tried a fair few nodes to try figure this out but to no avail. How can I get the intersection point between the space and the tray (top and bottom) and then split and what packages might i need to do this ?

Any direction on this would be greatly appreciated.


This is as far as I got so far