How to set several face to array in sort

Hi there, as you can see i have some faces that should place in array.
what’s the important is that face should pushed in seriate.

For example assuming the faces are placed along x-axis, you can sort the faces by x-coordinates of its
leftistleftmost’ vertices order.

#This will return the x-coordinate of the most 'left' located vertex
def the_leftmost(vertices)
  vertices.min{|a, b| a.position.x <=> b.position.x}.position.x
end

model = Sketchup.active_model
faces = model.entities.grep(Sketchup::Face)
sorted_faces = faces.sort{|a, b|
    the_leftmost(a.vertices) <=> the_leftmost(b.vertices)
  }

Edited: Wording suggestion by @DanRathbun below.
(By no means did I want to involve politics. :blush:)

4 Likes

We actually say leftmost. A leftist is a person with an extreme left of center political position.

1 Like