using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using GeometryExtensions;
[assembly
: CommandClass
(typeof(EllipseToPolylineSample
.CommandMethods))]
namespace EllipseToPolylineSample
{
public class CommandMethods
{
[CommandMethod("EL2PL", CommandFlags.Modal)]
public void EllipseToPolyline()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityOptions peo
= new PromptEntityOptions
("\nSelect an ellipse: "); peo.SetRejectMessage("Only an ellipse.");
peo
.AddAllowedClass(typeof(Ellipse
),
true); PromptEntityResult per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK) return;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
Ellipse ellipse = (Ellipse)tr.GetObject(per.ObjectId, OpenMode.ForWrite);
Polyline pline = ellipse.ToPolyline();
btr.AppendEntity(pline);
tr.AddNewlyCreatedDBObject(pline, true);
ellipse.Erase();
tr.Commit();
}
}
}
}