How to create intersection line from selected entities only

I am trying to find intersect line between 2 entities, similar to “Intersect With Selection” in SketchUp but currently using intersect_with function can only do function like “Intersect With Model” for me.

As picture showing above, I want intersection line from the selected entities only when I trying to use intersect_with function, it’s give me intersection lines from the above one that I’m not choose also.

I’m not sure how what value I should put in entities2 as in document
Class: Sketchup::Entities — SketchUp Ruby API Documentation
or else is there anyways that can help me out.

mod = Sketchup.active_model
ents = Sketchup.active_model.active_entities
sel = mod.selection
g = sel.first # The group in which connected the others together.
trans1 =
trans2 = g.transformation
line = ents.intersect_with(true, trans1, g.entities, trans2, true, g)

Here is my code that I get the result similar like “Intersect With Model”

Read the following API tracker issue thread …

There’ s some code from your forum that actually work like i want.

  def intersect(cutter_group, mesh_group, result_group)
    # transformation from mesh to cutter
    tr0 = cutter_group.transformation.inverse * mesh_group.transformation
    # transformation from result to cutter
    tr1 = cutter_group.transformation.inverse * result_group.transformation
    mesh_group.entities.intersect_with(false, tr0, result_group.entities, tr1, true, cutter_group.entities.to_a)

I’m still confuse how tr0 and tr1 work and what exactly transform1 for. Do you have any doc I can seek out or can you explain furthermore.

Your forum...

As soon as you read the forum, “his” forum becomes “yours”, because the essence of the forum is that the participants form (create) it, whether they only read or write too.

I don’t myself. The example you speak of was written by @CAUL

It is an incredibly powerful method, but also massively confusing. As said in that issue thread, there are over 50 hits here in the Developers forum if you search on “intersect_with”.