Finding all connected groups

Dear Dezmo,

I run your following codes for 2 cases. As you can see in photo it works for lower case but cannot work for upper case. Would you please let me know problem. Also I will be highly appreciate if you can explain code a little.

          2.times{
            ent.grep(Sketchup::Edge).to_a.each{|e|
              next unless e.valid?
              if e.start.edges.size == 1 || e.end.edges.size == 1 
                e.erase!
                next
              end
              next if e.faces.size != 2
              e.erase!         
            }

I also do some test on codes. Following codes works but I am not sure it is right or not.

               e.erase! if e.faces.size > 1

Yes this is correct for removing dividing edges. Example …

ent.grep(Sketchup::Edge) do |edge|
  edge.erase if edge.faces.size > 1
end

FYIEnumerable#grep is a block form iterator method. It produces an array so you need not use .to_a and you need not use .each as it is already an Array#each iterator.

1 Like