If you set the properties of the ellipse in the below manner, it won’t work because the Center cannot be set for a curve that still does not have its start and end point defined.
This does not work :
myEllipse = New Ellipse()
myEllipse.Center = New Point3d(0.0, 0.0, 0.0)
myEllipse.StartPoint = New Point3d(-10, 0, 0)
myEllipse.EndPoint = New Point3d(10, 0, 0)
myEllipse.RadiusRatio = 2.0
This is “as designed” – The call to StartPoint and EndPoint will throw an exception when the curve has no start point and end point. Use the HasStartPoint and HasEndPoint properties before calling StartPoint and EndPoint.
The way to create an ellipse is to use the constructor of ellipse class and pass the parameters.
For example:
Ellipse myEllipse = new Ellipse(center, normal, majorAxis, radiusRatio, startAng, endAng);
Here is a sample code :
[CommandMethod("CreateEllipse")]
static public void CreateEllipseMethod()
{
Document doc
= Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction tr
= db.TransactionManager.StartTransaction())
{
BlockTable bt = tr.GetObject(
db.BlockTableId,
OpenMode.ForRead,
false
) as BlockTable;
BlockTableRecord modelSpace =
tr.GetObject(
bt[BlockTableRecord.ModelSpace],
OpenMode.ForWrite,
false
) as BlockTableRecord;
Point3d center = Point3d.Origin;
Vector3d normal = Vector3d.ZAxis;
Vector3d majorAxis = 100 * Vector3d.XAxis;
double radiusRatio = 0.5;
double startAng = 0.0;
double endAng = 360 * Math.Atan(1.0) / 45.0;
Ellipse ellipse = new Ellipse(center,
normal,
majorAxis,
radiusRatio,
startAng,
endAng
);
// The following lines don't work!!
//Ellipse ellipse = new Ellipse();
//ellipse.SetDatabaseDefaults();
//ellipse.Center = Point3d.Origin;
//ellipse.StartPoint = new Point3d(-10.0, 0.0, 0.0);
//ellipse.EndPoint = new Point3d(10.0, 0.0, 0.0);
//ellipse.RadiusRatio = 2.0;
//ellipse.ColorIndex = 1;
ellipse.ColorIndex = 1;
modelSpace.AppendEntity(ellipse);
tr.AddNewlyCreatedDBObject(ellipse, true);
tr.Commit();
}
}

Leave a Reply