Grepping for faces


I’m trying to apply textures (materials) to various faces of an LVL board.

I am trying to apply a specific material to the edge face of the board.

My initial code looks like this:

group1faces = entities1.grep(Sketchup::Face)
group1faces[2].material = @Lvl_mat
group1faces[3].material = @Lvl_mat

The problem is to determine which faces are the narrow face of the board. They are always less than 2" in width and they are always oriented on the X-Y plane.

I’m sure I’ve seen a similar algorithm or Grep expression that can do this sort of thing but again my search came up empty.


You could test the normal vector direction of the faces to see which ones point the way you want. Ones in the XY plane will have their normal parallel to the z axis.


Will these faces be the smallest in terms of area? If so then that’s something you can use to sort them by. I’m assuming this isn’t the case.

If you have the dimensions for the board you can look for faces with an area specific to those faces… could potentially be dangerous depending on the possible sizes for these boards as faces other than what you’re looking for could also have that same area.

You said they are always oriented on the X-Y plane. Ultimately the way I would choose to do it would be to pick the faces based on their normals.
I’m hesitant to provide a code example for fear of leading you astray but figure someone will be here to correct me if so.

group1faces.find_all {|face| face.normal == [0,0,1] || face.normal == [0,0,-1]}


You explain the algorithm quite well, …

… just write it within a find loop …

ends = group1faces.find_all do |face|
  face.normal.parallel?(Z_AXIS) &&
  face.edges.any? {|edge| edge.length < 2.inch }