创建圆弧对象
 
 

This example creates an arc in Model space with a center point of (6.25,9.125,0), a radius of 6, start angle of 1.117 (64 degrees), and an end angle of 3.5605 (204 degrees).

本例在模型空间中创建一个中心点在 (6.25,9.125,0),半径为6,起始角度为1.117(64度),终点角度为3.5605(204度)的圆弧。

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
 
<CommandMethod("AddArc")> _
Public Sub AddArc()
  '' 获得当前文档和数据库   Get the current document and database
  Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
  Dim acCurDb As Database = acDoc.Database
 
  ''启动一个事务   Start a transaction
  Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
 
      '' 以只读方式打开块表   Open the Block table for read
      Dim acBlkTbl As BlockTable
      acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
 
      '' 以写方式打开模型空间块表记录   Open the Block table record Model space for write
      Dim acBlkTblRec As BlockTableRecord
      acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
                                      OpenMode.ForWrite)
 
      '' 创建一个中心点在 (6.25,9.125,0),半径为6,起始角度为1.117(64度),终点角度为3.5605(204度)的圆弧。   Create an arc that is at 6.25,9.125 with a radius of 6, and
      '' starts at 64 degrees and ends at 204 degrees
      Dim acArc As Arc = New Arc(New Point3d(6.25, 9.125, 0), _
                                 6, 1.117, 3.5605)
 
      acArc.SetDatabaseDefaults()
 
      '' 添加新对象到块表记录和事务中   Add the new object to the block table record and the transaction
      acBlkTblRec.AppendEntity(acArc)
      acTrans.AddNewlyCreatedDBObject(acArc, True)
 
      '' 保存新对象到数据库中   Save the new object to the database
      acTrans.Commit()
  End Using
End Sub

C#

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
 
[CommandMethod("AddArc")]
public static void AddArc()
{
  // 获得当前文档和数据库   Get the current document and database
  Document acDoc = Application.DocumentManager.MdiActiveDocument;
  Database acCurDb = acDoc.Database;
 
  // 启动一个事务  Start a transaction
  using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
  {
      // 以只读方式打开块表   Open the Block table for read
      BlockTable acBlkTbl;
      acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                   OpenMode.ForRead) as BlockTable;
 
      // 以写方式打开模型空间块表记录   Open the Block table record Model space for write
      BlockTableRecord acBlkTblRec;
      acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                      OpenMode.ForWrite) as BlockTableRecord;
 
      // 创建一个中心点在 (6.25,9.125,0),半径为6,起始角度为1.117(64度),终点角度为3.5605(204度)的圆弧。   Create an arc that is at 6.25,9.125 with a radius of 6, and
      // starts at 64 degrees and ends at 204 degrees
      Arc acArc = new Arc(new Point3d(6.25, 9.125, 0),
                          6, 1.117, 3.5605);
 
      acArc.SetDatabaseDefaults();
 
      // 添加新对象到块表记录和事务中   Add the new object to the block table record and the transaction
      acBlkTblRec.AppendEntity(acArc);
      acTrans.AddNewlyCreatedDBObject(acArc, true);
 
      // 保存新的直线到数据库中    Save the new line to the database
      acTrans.Commit();
  }
}
VBA/ActiveX 代码参考