How to draw a ellipse useing ruby api?

i’d like to draw a ellipse in su using ruby, but it seems having no api to draw ellipse.

That’s right. You have to write your own procedure.
Just as the circle is made of edges, you have to calculate the points of the ellipse and connect them with edges.
Like others did:

Here, study this …

module Naive
  module Geom

    extend self

    def ellipse(center, normal, major_axis, minor_axis, numsegs)
      model = Sketchup.active_model
        center =
        normal =
        ents  = model.active_entities
        grp   = ents.add_group
        gents = grp.entities
        gents.add_circle(center, Z_AXIS, major_axis/2.0, numsegs.to_i)
        t = Geom::Transformation.scaling(1.0, minor_axis.to_f/major_axis.to_f, 1.0)
        unless normal == Z_AXIS
          rot = Geom::Transformation.rotation(
            center, Z_AXIS.cross(normal), Z_AXIS.angle_between(normal)
          grp.transformation= grp.transformation * rot
      return grp
    rescue => error
      puts error.inspect
    end ### ellipse()


Example call:

ellipse = Naive::Geom.ellipse([3,5,7], [1,1,1], 20, 13.2, 36)

You can explode the group afterwards.

1 Like

UPDATED above example to wrap within an undo operation.

For those who are wondering what @DanRathbun 's snippet does: it replicates in Ruby what you would do to draw an ellipse by hand in SketchUp. That is, it draws a circle, scales it along the minor axis, then rotates it to the specified normal. The scaling will produce non-uniform edge length in the ellipse, but it is much much more complicated math to create an ellipse with equal length edges!