Add face with edges and curves

I’m trying to push/pull a face using a combination of an arc (curve) and some straight edges:

edgearray = entities40.add_arc center_pt1, xaxis1, normal1, radius1, start_angle1, end_angle1, 12
edge1 = edgearray[0]
arccurve1 = edge1.curve`
new_face41 = entities40.add_face(edge3, edge2, edge1, arccurve1)
new_face41.pushpull -@Wallsheaththk

However it returns this error.

Error: #<TypeError: wrong argument type (expected Sketchup::Edge)>

Does the edges and arcurve need to be in a specific order?

new_face41 = entities40.add_face(edge3, edge2, edge1, arccurve1.edges)

john

1 Like

When I try this code I get:

Error: #<TypeError: wrong argument type (expected Sketchup::Edge)>

This doesn’t work either:

new_face41 = entities40.add_face(line3, line2, line1, arccurve1.edges).flatten

The name of the variables are actually line1 etc… however this is not the reason for the error.

Entities#add_face doesn’t have a variant that allows a mixture of individual edges with an Array of edges. You might unshift edge3, edge2, edge1 onto the front of the Array and then pass the Array as a single argument to add_face.

1 Like

If the face coincides with the edge of the sheathing (at the bottom), I can actually do this instead:

new_face41 = (line1.faces)[0]

This will get the face which I can then push/pull to create the door opening. The only problem is that I’m not guaranteed that the first face in the array is the correct face. However, after testing this about 20 times it still has not selected the larger face of the solid.

When I do this:

halfround_path = [line3, line2, line1, arccurve1.edges].flatten
puts "#{halfround_path}"
new_face41 = entities40.add_face(halfround_path)

I get this:

[#<Sketchup::Edge:0x0000000feba4b0>, #<Sketchup::Edge:0x0000000feba500>, #<Sketchup::Edge:0x0000000feba550>, #<Sketchup::Edge:0x0000000feba780>]
Error: #<NoMethodError: undefined method `pushpull' for nil:NilClass>

The arc is composed of 12 edges so somehow the “edges” method must not be picking them all up.

This is very odd, this chunk of code:

edgearray = entities40.add_arc center_pt1, xaxis1, normal1, radius1, start_angle1, end_angle1, 12
edge1 = edgearray[0]
arccurve1 = edge1.curve
arcedges = arccurve1.edges
puts "#{arcedges}\n"

produces this:

[#<Sketchup::Edge:0x0000000fc51318>]

Shouldn’t I be seeing an array of 12 edges?

Which brings me to my next question, why do I need to go through all of these steps to get the edges that make up the arc when the variable edgearray already contains this array of edges? … ??

The whole curve and arcCurve thing confuses the heck out of me.

That is actually my 1st question. Just because some obscure example does this kind of thing doesn’t mean you cannot use your own best judgement to write better code.

Of course not, because neither the Sketchup::Face class nor the NilClass have a #flatten method. (You’re trying to call Array#flatten method upon the result of the add_face method, which is not an array.)

It is more usual to use the “splat” operator to convert arrays to parameter lists (and visa versa.)

new_face41 = entities40.add_face(line3, line2, line1, *edgearray)
if new_face41
  # add face was successful
end

… but you can also do …

new_face41 = entities40.add_face( [line3, line2, line1, edgearray].flatten )
if new_face41
  # add face was successful
end

… or even …

new_face41 = entities40.add_face( [line3, line2, line1] + edgearray )
if new_face41
  # add face was successful
end

You must be sure to check the result of the add_face call or check the the line arguments and the arc are one the same plane. I’m not sure but the add_face call might even raise an exception if the args are not coplanar.

So always verify the object is a valid face before calling #pushpull on it.

I can check the final array of edges I send to the add_face command and everything looks good, I also know they form a coplanar face, but for some reason the linear edges and the arc edges don’t seem to play well together when I pass them in one array to the add_face method.

I’ve tried various code combinations like those shown above but to no avail, I’m stumped.

Got a complete runnable example? I can step it through the debugger to see why/where it chokes.

1 Like

I did come up with a workaround but it is kind of a hack in my opinion. I will try to provide a full example of this where it chokes, but theoretically shouldn’t.

1 Like