How can I split a face by a group

Dear Friends,
Cn you lead me how to split a face by a group. I wrote following code for start. attached photo can show you my requirement.

mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
pt = []
pt[0] = [10, 10, 10]
pt[1] = [10, -10, 10]
pt[2] = [-10, -10, 10]
pt[3] = [-10, 10, 10]
grp = mod.active_entities.add_group
grp_face = grp.entities.add_face(pt)
grp_face.pushpull 20

#Main Codes
pt[0] = [5, 100, 0]
pt[1] = [5, -100, 0]
pt[2] = [-5, -100, 0]
pt[3] = [-5, 100, 0]
face1 = ent.add_face(pt)
#How can face1 split to 2 separate faces by grp? 

thank you in advance,

ent.intersect_with( false, IDENTITY, ent, IDENTITY, false, grp )
edges_to_erase = ent.grep(Sketchup::Edge).find_all{|edge|
  edge.faces.size == 1 && edge.start.edges.size == 3 && edge.end.edges.size == 3
}
ent.erase_entities( edges_to_erase )

Thank you for your attention. I should explain more. We don’t know in face1 we have any group or not also we don’t know place of group. I just used “grp” to have an example for my problem. One way is check all groups for intersection. Do you know better way?

I really like “edges.size == 3” idea. It can help my future codes a lot.

Yes that is good idea. Then you have to deal with the face parent group, and the entities object where you want the intersection lines to appear, in the .intersect_with method…

Be careful, this only works if the group is “bigger” than the face and/or not overlapping…

1 Like