Some edges not deleted!

Dear Friends,

pt = [[0, 0, 0], [2, 0, 0], [4, 0, 0], [6, 0, 0], [8, 0, 0], [10, 0, 0]]
rpt = [[0, 8, 0], [2, 8, 0], [4, 8, 0], [6, 8, 0], [8, 8, 0], [10, 8, 0]]
grp = Sketchup.active_model.active_entities.add_group
for i in 0...5
  face = grp.entities.add_face [rpt[i], pt[i], pt[i + 1], rpt[i + 1]]
  face.reverse! if face.normal == [0, 0, -1]
  face.pushpull i + 1
  face = grp.entities.add_face [rpt[i], pt[i], pt[i + 1], rpt[i + 1]]
  face.reverse! if face.normal == [0, 0, 1]
end
grp.entities.grep(Sketchup::Edge) do |e|
  e.erase! if e.faces.first.normal == e.faces.last.normal
end  

You can see result in attached picture.


As you can see in picture some edges not deleted!!! Can you help me for this problem?
Thank you in advance.

Following code solve my problem but I don’t know why I have to run codes 2 times.

2.times do
  grp.entities.grep(Sketchup::Edge) do |e|
    e.erase! if e.faces.first.normal == e.faces.last.normal
  end  
end

If an edge has 3 faces - e.g. an internal partition face - then sometimes you code will fail once…
Repeating it then traps those exceptions.

If you want to delete the edges you show then consider using:

grp.entities.grep(Sketchup::Edge){|e|
  e.erase! if e.faces.length > 2
}
1 Like

This is your original stairs with internal faces.
image

(The rest is answered by TIG while I typed)

1 Like

Of course, my solution falls apart once you delete some edges, so subsequent edges tested don’t match…
You can collect them and do it in one go !
This avoids any redoing…

togos=[]
grp.entities.grep(Sketchup::Edge){|e|
  togos << e if e.faces.length > 2
}
grp.entities.erase_entities(togos) if togos[0]
2 Likes

The code snippet from TIG will erase more edges, than necessary.

In this particular case this one works better…

grp.entities.grep(Sketchup::Edge) do |e|
  e.erase! if e.faces.first.normal == e.faces.last.normal || e.faces.length > 2
end
1 Like

You can avoid this situation if you draw the side (profile) face, and pushpull in the direction of the Y_AXIS to the width of your stair tread.

:bulb:

2 Likes

Thank you all. I understand my problem and solution completely.