Generally yes.
However, in this case it is more complex because it is one of the Entities
collections and the calls to edge.erase!
cause the SketchUp engine to also erase faces if the deleted edge was on the outer loop of a face.
Look back and you’ll see the error was that calls to edge.faces
returned empty arrays that return nil
for .first
and .last
. So also a conditional like next if edge.faces.empty?
can be used to avoid this error.
But is is still safer to collect the edges to be erased and use the bulk eraser when dealing with an API Entities
collection.
ents = grp.entities
ents.erase_entities(
ents.grep(Sketchup::Edge).select { |e| e.faces.size != 2 }
)
In the above example, e.faces.size
will return 0
for an empty array, so there will be no error and any edge without a face will be chosen.