欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

AutoCAD .Net 创建椭圆Ellipse

程序员文章站 2022-03-31 14:52:32
...

以下代码展示:
往模型空间中添加一个椭圆。椭圆的中心为(0, 0, 0),长轴半径为100,短轴半径为60,圆弧所在平面为XOY平面,起始角为0度,终止角为360度。
设置椭圆的图层、颜色、线型、线宽请参考文章AutoCAD .Net 创建直线Line

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Colors;

[CommandMethod("NewEllipse")]
public static void NewEllipse()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;

    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        //-------------------------------
        // 获取模型空间
        //-------------------------------
        BlockTable blockTbl = tr.GetObject(
            db.BlockTableId, OpenMode.ForRead) as BlockTable;
        BlockTableRecord modelSpace = tr.GetObject(
            blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

        //-------------------------------
        // 创建椭圆
        //-------------------------------
        Ellipse ellipse = new Ellipse();
        ellipse.Set(
            new Point3d(0, 0, 0),     // Center
            new Vector3d(0, 0, 1),    // Normal
            new Vector3d(100, 0, 0),  // Major Axis
            0.6,                      // Radius radio
            0,                        // Start Angle
            Math.PI * 2               // End Angle
        );

        //----------------------------
        // 添加到模型空间并提交到数据库
        //-------------------------------
        modelSpace.AppendEntity(ellipse);
        tr.AddNewlyCreatedDBObject(ellipse, true);

        tr.Commit();
    }
}

通过设置椭圆的起始角度和终止角度可以创建椭圆弧。

相关标签: AutoCAD C#