Multi Level Curve Boolean Union

I have to calculate the union of a closed planar curves arranged on several levels: This script only works with one level. there are solutions?

Thank you.


example.3dm (51.5 KB)

import rhinoscriptsyntax as rs

curve_ids = rs.GetObjects(“Select curves to union”, rs.filter.curve)
if curve_ids and len(curve_ids)>0.1:
    result = rs.CurveBooleanUnion(curve_ids)
    if result: rs.DeleteObjects(curve_ids)

Your best bet is to find co-planar curves and then Boolean them set by set.