Remove inner faces programmatically

that was too simple, I should have re-saved the file before re-testing…

now I’ll have to have a proper look…

john

HAHA! at least I’m not an idiot.

This is the optimized version; the processing speed is faster.

model = Sketchup.active_model
ents  = model.active_entities
sel   = model.selection

# 清除当前选择集
sel.clear unless sel.empty?

# 获取所有面
faces = ents.grep(Sketchup::Face)

# 将被包围的内部面选中
faces.each do |face|
  # 检查面是否只被一个面包围,如果是则表示是外部面
  if face.outer_loop.edges.all? { |edge| edge.faces.length == 1 }
    sel.add(face)
  end
end

# 删除未选中的面(即内部面)
model.start_operation('删除内部面', true)
faces.each do |face|
  face.erase! unless sel.include?(face)
end
model.commit_operation
1 Like