This example creates a circle in Model space using three points (0, 0, 0), (5, 5, 0), and (10, 0, 0). The spline has start and end tangents of (0.5, 0.5, 0.0).
本例在模型空间中创建一个使用三个点 (0, 0, 0), (5, 5, 0), 和 (10, 0, 0)创建的圆。样条曲线的起始和终止切向为(0.5, 0.5, 0.0)。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
<CommandMethod("AddSpline")> _
Public Sub AddSpline()
'' 获得当前文档和数据库 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)
'' 定义样条曲线的固定点 Define the fit points for the spline
Dim ptColl As Point3dCollection = New Point3dCollection()
ptColl.Add(New Point3d(0, 0, 0))
ptColl.Add(New Point3d(5, 5, 0))
ptColl.Add(New Point3d(10, 0, 0))
''从点(0.5,0.5,0)获得三维矢量 Get a 3D vector from the point (0.5,0.5,0)
Dim vecTan As Vector3d = New Point3d(0.5, 0.5, 0).GetAsVector
'' Create a spline through (0, 0, 0), (5, 5, 0), and (10, 0, 0) with a
'' start and end tangency of (0.5, 0.5, 0.0)
Dim acSpline As Spline = New Spline(ptColl, vecTan, vecTan, 4, 0.0)
acSpline.SetDatabaseDefaults()
'' 添加新对象到块表记录和事务中 Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acSpline)
acTrans.AddNewlyCreatedDBObject(acSpline, True)
'' 保存新对象到数据库中 Save the new object to the database
acTrans.Commit()
End Using
End Sub
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
[CommandMethod("AddSpline")]
public static void AddSpline()
{
// 获得当前文档和数据库 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;
// 定义样条曲线的固定点 Define the fit points for the spline
Point3dCollection ptColl = new Point3dCollection();
ptColl.Add(new Point3d(0, 0, 0));
ptColl.Add(new Point3d(5, 5, 0));
ptColl.Add(new Point3d(10, 0, 0));
//从点(0.5,0.5,0)获得三维矢量 Get a 3D vector from the point (0.5,0.5,0)
Vector3d vecTan = new Point3d(0.5, 0.5, 0).GetAsVector();
// Create a spline through (0, 0, 0), (5, 5, 0), and (10, 0, 0) with a
// start and end tangency of (0.5, 0.5, 0.0)
Spline acSpline = new Spline(ptColl, vecTan, vecTan, 4, 0.0);
acSpline.SetDatabaseDefaults();
// 添加新对象到块表记录和事务中 Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acSpline);
acTrans.AddNewlyCreatedDBObject(acSpline, true);
// 保存新的直线到数据库中 Save the new line to the database
acTrans.Commit();
}
}