How can I get the outer_loop of multiple faces?


#1

Take this picture for reference:

http://imgur.com/L0fIZYT

Usually, I use the outer_loop of a face to get the geometrie of a “wall” (blue and white faces combined). In this case, there is a recess in the loop due the other face splitting the edge on the side. The BoundingBox I get after combining the faces on that “wall” to a group does only work in very specific situations. Any pointers?


Sorting edges/vertices
#2
require 'set'

module Example

  # @return [Array<Sketchup::Edge>]
  def self.entity_set_border(entities)
    # Collect all faces in selection set for fast lookup.
    selection_faces = Set.new(entities.grep(Sketchup::Face))

    # Collect all edges for the faces in the selection set for fast lookup.
    edges = Set.new
    selection_faces.each { |face| edges.merge(face.edges) }

    # Find the edges that connects to only one of the faces in the selection.
    border = edges.select { |edge|
      num_faces = edge.faces.count { |face| selection_faces.include?(face) }
      num_faces == 1
    }

    border
  end

  # Example.select_selection_border
  def self.select_selection_border
    model = Sketchup.active_model
    border = self.entity_set_border(model.selection)
    model.selection.clear
    model.selection.add(border)
    nil
  end

end # module

Detect the doors exists in which face
2d DXF to 3d model automation
#3

Thanks, that’s exactly what I needed, never made the connection of using the number of faces connected to the outer edges.


#4

Thomas, doesn’t that code assume there are no holes in the faces? That is, an edge of a hole will also have only one connected face?


#5

True that - hence the methods called “border” and not “outer_loop”.