Creating intersection lines within Groups

Hello.

I am trying to write a routine that will create intersection lines for every group in a model based on an arbitrary intersection plane but the intersections do not end up in the correct location. I think I am not handling the transformations properly!

Any advice would be greatly appreciated!

# create the a circle the size of the model bounds and fill it with a face
cutting_circle = Sketchup.active_model.active_entities.add_group
cutting_circle.name = "CUTTING_CIRCLE"
cutting_circle.transformation = Geom::Transformation.new Geom::Point3d.new 0,0,0
cutting_circle.entities.add_circle(
    [
        Sketchup.active_model.bounds.center[0],
        Sketchup.active_model.bounds.center[1],
        48 # 48 inches above the origin
    ], #center
    Z_AXIS,
    [Sketchup.active_model.bounds.width,Sketchup.active_model.bounds.depth].max # radius
)
cutting_circle.entities.grep(Sketchup::Edge).each{|e|
    e.find_faces
}

# create level transformation trackers
parent_stack = [Geom::Transformation.new()]
current_depth = 0

# iterate all groups in the model and intersect with them
Sketchup.active_model.entities.grep(Sketchup::Group){|this_group|

    # track context
    current_depth += 1
    parent_stack[current_depth] = this_group.transformation
    parent_context = parent_stack.inject(:*)
    current_trans = parent_context*this_group.transformation

    # create a group to receive the section geometry
    section_container = this_group.definition.entities.add_group
    section_container.transformation = current_trans

    # execute the cut
    cutting_circle.entities.intersect_with(
        false, #if true intersection lines will be put inside of groups and components within section_container
        this_group.transformation, # transformation for group to intersect with
        section_container, #where to place the intersection edges
        section_container.transformation, # transformation for section_container
        false, # if true, intersects hidden geometry in group to intersect with
        this_group # the group to intersect with
    )

    parent_stack.pop()
    current_depth -= 1

} # end of everything each iteration

Sketchup.active_model.active_entities.erase_entities cutting_circle```