I noticed that Entities#add_face fails (returns a nil object) when I use an edge array from Entities#add_edges as the input parameter.
This demonstrates the behavior:
#require 'sketchup.rb'
def demonstrate_bug
entities = Sketchup.active_model.entities
### CASE 1: Face from Edges via Entities#add_line ###
p1 = Geom::Point3d.new([1,1,0])
p2 = Geom::Point3d.new([4,7,0])
p3 = Geom::Point3d.new([7,1,0])
e1 = entities.add_line(p1,p2)
e2 = entities.add_line(p2,p3)
e3 = entities.add_line(p3,p1)
edges1 = [e1, e2, e3]
f1 = entities.add_face(edges1)
result1 = f1.is_a?(Sketchup::Face) ? 'PASS' : 'FAIL'
vertex_equal_1 = edges1[0].start == edges1[-1].end
vertex_colocated_1 = edges1[0].start.position == edges1[-1].end.position
puts "Case 1: Face via edges from Entities#add_line: #{result1}"
puts "\tStart/end vertex objects equal: #{vertex_equal_1}"
puts "\tStart/end vertex positions equal: #{vertex_colocated_1}"
### CASE 2: Face from Edge array via Entities#add_edges ###
p4 = Geom::Point3d.new([11,1,0])
p5 = Geom::Point3d.new([14,7,0])
p6 = Geom::Point3d.new([17,1,0])
edges2 = entities.add_edges(p4, p5, p6, p4)
f2 = entities.add_face(edges2)
result2 = f2.is_a?(Sketchup::Face) ? 'PASS' : 'FAIL'
vertex_equal_2 = edges2[0].start == edges2[-1].end
vertex_colocated_2 = edges2[0].start.position == edges2[-1].end.position
puts "Case 2: Face via edges from Entities#add_edges: #{result2}"
puts "\tStart/end vertex objects equal: #{vertex_equal_2}"
puts "\tStart/end vertex positions equal: #{vertex_colocated_2}"
### CASE 3: Face from Points via Entities#add_face(pts_array) ###
p7 = Geom::Point3d.new([21,1,0])
p8 = Geom::Point3d.new([24,7,0])
p9 = Geom::Point3d.new([27,1,0])
f3 = entities.add_face(p7, p8, p9)
result3 = f3.is_a?(Sketchup::Face) ? 'PASS' : 'FAIL'
puts "Case 3: Face via points, using Entities#add_face: #{result3}"
end
When I run it I get the following:
Best guess is that one or both of the following are happening:
- The
add_edges
method is returning edges which create a loop spatially but not by reference to the same vertex object. (This is definitely the caseâwhether itâs somehow my fault isnât clear to me.) - The
add_face
method is only doing loop testing by object equality of vertices, not position equality.
If Iâm wrong and this is expected behavior Iâd be interested to know.