The code should not assume that the faces
will always belong to the Sketchup.active_model.entities
collection. As @TIG did above, you should use obj
.parent.entities
:
def self.fix(faces)
# All faces must be within same parent entities:
return unless faces.map(&:parent).uniq.count == 1
vertices = faces.map(&:vertices).uniq
model = vertices.first.model
model.start_operation("Fix Faces",true)
# Generally speaking, seek to transform vertices using bulk method
# to prevent face triangulation:
faces.first.parent.entities.transform_entities(IDENTITY, vertices)
model.commit_operation
end