You may be missing the idea that you could reuse the same code to draw each 90 degree corner, by just rotating the x axis vector for each corner.
So going clockwise …
module CraftyHippo
extend self
def draw_arc(ents,center,vector,radius)
ents.add_arc( center, vector, Z_AXIS, radius, 90.degrees, 0.degrees ).first.curve
end
def draw_round_square(ipoint,width,height,radius)
# ipoint = insertion point at lower left
xside = width - (2*radius)
yside = height - (2*radius)
arcs = []
model = Sketchup.active_model
ents = model.active_entities
#
model.start_operation("Draw Rounded Square")
#
center = ipoint.transform([radius,radius,0])
arcs << draw_arc(ents,center,[-1,0,0],radius)
#
center = center.transform([0,yside,0])
arcs << draw_arc(ents,center,[0,1,0],radius)
#
center = center.transform([xside,0,0])
arcs << draw_arc(ents,center,[1,0,0],radius)
#
center = center.transform([0,-yside,0])
arcs << draw_arc(ents,center,[0,-1,0],radius)
#
for i in 1..4
ents.add_line(
arcs[i-1].last_edge.end.position,
arcs[ i==4 ? 0 : i ].first_edge.start.position
)
end
#
arcs[0].first_edge.find_faces
#
model.commit_operation
#
end
end
And running it at the console …
CraftyHippo.draw_round_square(ORIGIN,5,5,1)
P.S. - In the example above I’m using arrays in place of points, vectors and transformations.
The API has made the Array class compatible with these classes of objects. Ie …
Class: Array — SketchUp Ruby API Documentation
The SketchUp Array class adds additional methods to the standard Ruby Array class. Specifically, it contains methods allowing an array to behave just as a Geom::Vector3d or Geom::Point3d object (which can be thought of as arrays of 3 coordinate values). Therefore, you can use the Array class in place of a Geom::Point3d or Geom::Vector3d as a way to pass coordinate values.