Search code examples
c#autocadautodeskobjectarx

How to convert an ellipse to a polyline in Objectarx C#


Currently I have a script that creates an ellipse, and Im trying to add the ability to adjust line thickness. Since from my knowledge you cannot do this normally with an ellipse, Im trying to convert it to a Polyline using the PELLIPSE variable. However, even with the variable setting, it doesn't seem to convert over. Is there an easier way of doing this, or a potential fix to this issue?

Current Ellipse code:

 public override Entity getAcObj()
        {
            return
                new Ellipse(
                        new Point3d(Markup.XCoord, Markup.YCoord, 0),
                        Vector3d.ZAxis,
                        new Vector3d((Markup.Locations[0].XCoord - Markup.Locations[1].XCoord) / 2, -(Markup.Locations[2].YCoord - Markup.Locations[3].YCoord) / 2, 0),
                        (Math.Abs(Markup.Locations[0].YCoord - Markup.Locations[3].YCoord) / 2)
                            / (Math.Abs(Markup.Locations[0].XCoord - Markup.Locations[1].XCoord) / 2),
                        0,
                        360 * Math.Atan(1.0) / 45.0
                    )
                {
                    Layer = Layer
                };
        }

PELLIPSE variable setting:

Application.SetSystemVariable("PELLIPSE", 1);

Solution

  • The PELLIPSE system variable acts only on the native ELLIPSE command. You could use it in combination with the Editor.Command() method but only for closed ellipses. Alternatively, you can use the GeometryExtensions library which provides a ToPolyline() extension method for the Ellipse type.

    var polyline = ellipse.ToPolyline();