Creating intersection lines within Groups


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"
cutting_circle.transformation = 0,0,0
        48 # 48 inches above the origin
    ], #center
    [Sketchup.active_model.bounds.width,Sketchup.active_model.bounds.depth].max # radius

# create level transformation trackers
parent_stack = []
current_depth = 0

# iterate all groups in the model and intersect with them

    # 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
        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

    current_depth -= 1

} # end of everything each iteration

Sketchup.active_model.active_entities.erase_entities cutting_circle```