Agreed. It would have been more intuitive if the #add_circle
method returned a closed Sketchup::Arcurve
object instead, and that class have a #inner_face
method.
It is too late now to change that (or the #add_arc
method) so we work with what they’ve given us, which is the Sketchup::Edge#curve
method.
Anyway, … there are several ways to do it, and some of the reference assignments can be skipped as they just eat time.
circle_array = entities40.add_circle( center_pt1, normal1, radius1, 24 )
if circle_array # nil if failure
face = circle_array[0].common_face(circle_array[3])
if face # nil if failure
# do some code
end
end
I choose to promote the use of non-adjacent edges of the circle, though it likely doesn’t matter which two edges of the circle you use. Ie, …
face = circle_array.first.common_face(circle_array.last)
Another approach …
before = entities40.grep(Sketchup::Face)
circle_array = entities40.add_circle( center_pt1, normal1, radius1, 24 )
added_faces = entities40.grep(Sketchup::Face) - before
if added_faces
is size 1, you’re done, otherwise you use Enumerable#find
and some boolean test to determine which face is the one you want. But the upper example is the more direct and easiest.
I show you this before and after array subtraction filtering method just because it is generic to many situations.
You can even create nifty block form methods that do this filtering …
def collect_added_faces( ents, &block )
#
before = ents.grep(Sketchup::Face)
# Call the block passing in the ents reference:
yield ents
ents.grep(Sketchup::Face) - before
#
end
def collect_added_entities( ents, &block )
#
before = ents.grep(Sketchup::Drawingelement)
# Call the block passing in the ents reference:
yield ents
ents.grep(Sketchup::Drawingelement) - before
#
end
And then to use them using your example variable names …
new_faces = collect_added_faces( entities40 ) do |ents|
ents.add_circle( center_pt1, normal1, radius1, 24 )
end