Finding Bottom Face

Dear Friends,
Following codes find bottom face of groups. when groups are closed loop problem will happen. You can see open loop and closed loop in photo.
code:…

        temp_grp = Sketchup.active_model.entities.add_group
        grp.entities.grep(Sketchup::Face) do |f|
          temp_grp.entities.add_face f.vertices if f.normal == [0, 0, -1]
        end
        temp_grp.material = "red"


I changed group position to show problem. Can you help me to know why it happen and how can I solve this problem?

Check out the face.loops, and face.outer_loop properties. Note that loops contains the outer_loop as well.

grp.entities.grep(Sketchup::Face) do |f|
  temp_grp.entities.add_face(f.outer_loop.vertices) if f.normal == [0, 0, -1]
  loops = f.loops.reject { |l| l == f.outer_loop }
  loops.each do |loop|
    face = temp_grp.entities.add_face(loop.vertices)
    face.erase!
  end
end
1 Like