How to break faces?

I write code to create two faces(copy & run in the builtin ruby console):

entities = Sketchup.active_model.entities

# create a red face
red_face = entities.add_face [
  [0,0,0],
  [0,10,0],
  [10,10,0],
  [10,0,0]
]
red_face.back_material = 'red'

# create a blue face
blue_face = entities.add_face([
  [5,5,0],
  [5,15,0],
  [15,15,0],
  [15,5,0]
])
blue_face.back_material = 'blue'
# TODO: break the intersection face

then the view is:

How to break the intersection face?

You can try:
group = entities.add_group(blue_face)
group.explode

2 Likes

Use Entities.intersect_with: Class: Sketchup::Entities — SketchUp Ruby API Documentation

If you create a group with entities, its much more efficient to create the group first and then add the geometry into it. Optimal way of creating groups via the API is different than from the UI.

2 Likes

Also note that add_group with parameters can produce crashes and other unexpected behavior if those entities aren’t in the active drawing context. I would advise to only use add_group with parameters when there is no other way.

1 Like

I second that.