EDIT … Please see this other thread using plane / vertex comparison …
Would something like this also work ?
# Erase redundant edges in an entities context. A face is redundant if it is
# used by more than 1 face and all it's faces have parallel normal vectors.
#
# @param context [Sketchup::Entities] can be any entities context (choose from:
# model.entities, model.active_entities, group.entities or definition.entities.)
#
# @return [Integer] count of deleted edges.
#
def erase_redundant_edges(context)
edge_list = context.grep(Sketchup::Edge)
redundant = edge_list.find_all do |e|
next false unless e.faces > 1
vector = e.faces.first.normal
e.faces.all? { |f| f.normal.parallel?(vector) }
end
unless redundant.empty?
context.model.start_operation('Remove redundant edges',true,false,true)
context.erase_entities(redundant)
context.model.commit_operation
end
redundant.count { |e| e.deleted? }
end
Edited: To put whole operation inside unless redundant.empty?
block.
Edit-2: Corrected first line to remove call to .entities
as context
should be an Sketchup::Entities
instance object. Added docsting for YARD. Adding return a count of deleted edges.
Edit-3: Corrected the erase_entities
line (in the operation) to remove .entities
call (as it is now an entities
context.)