编辑样条曲线
 
 

You can edit the properties of an open or closed spline, and even convert it to a polyline. Use the following properties to open or close a spline, change its control points, or reverse the direction of a spline:

用户可以编辑开放或封闭样条曲线的属性,并可以将它平滑转换为多段线。使用下列属性打开或闭合样条曲线,修改它的控制点或反转样条曲线的方向:

Degree

Returns the polynomial representation of the spline.
返回样条曲线的多项式表示的阶数。

EndFitTangent

Returns the end tangent of the spline as a directional vector.
返回样条曲线的端点切向作为方向矢量。

FitTolerance

Refits the spline to the existing points with new tolerance values.
使用新的公差值将样条曲线重新拟合至现有点。

NumControlPoints

Returns the number of control points for the spline.
获取样条曲线的控制点数目。

NumFitPoints

Returns the number of fit points for the spline.
获取样条曲线的拟合点数目。

StartFitTangent

Returns the start tangent for the spline.
返回样条曲线的起点切向。

In addition, you can use the following methods to edit splines:

另外,也可以使用下列方法编辑样条曲线:

InsertFitPointAt

Adds a single fit point to the spline at a given index.
添加一个单一的拟合点到样条曲线指定的索引处。

ElevateDegree

Increases the degree of the spline to the given degree.
将样条曲线的阶数提高到给定的阶数。

GetControlPointAt

Gets the control point of the spline at a given index. (Gets one control point only.) The NumControlPoints property contains the number of control points of the spline.
返回样条曲线指定索引处的控制点。(仅获得一个控制点。)NumControlPoints 属性包含样条曲线的控制点数量。

GetFitPointAt

Gets the fit point of the spline at a given index. (Gets one fit point only. To query all the fit points of the spline, use the FitData property and then query the FitData object returned with its GetFitPoints member function.) The NumFitPoints property contains the number of fit points of the spline.
获得样条曲线指定索引处的拟合点。(仅获得一个拟合点。若要查询样条曲线的所有拟合点,请使用) FitData 属性然后用返回的 FitData 对象的 GetFitPoints成员函数进行查询)NumFitPoints 属性包含样条曲线的拟合点数。

RemoveFitPointAt

Deletes the fit point of a spline at a given index.
删除样条曲线指定索引处的拟合点数。

ReverseCurve

Reverses the direction of a spline.
反转样条曲线的方向。

SetControlPointAt

Sets the control point of the spline at a given index.
设置样条曲线指定索引处的控制点。

SetFitPointAt

Sets the fit point of the spline at a given index. (Sets one fit point only. To change all the fit points of the spline, use the FitPoints property.)
设置样条曲线指定索引处的拟合点。(仅设置一个拟合点。若要修改样条曲线的所有拟合点,请使用 FitPoints 属性。)

SetWeightAt

Sets the weight of the control point at a given index.
设置指定索引处控制点的权值。

Use the following read-only properties to query splines:

使用下列只读属性来查询样条曲线:

Area

Gets the enclosed area of a spline.
获得样条曲线可封闭区域的面积。

Closed

Indicates whether the spline is open or closed.
指示此样条曲线为开放还是闭合。

Degree

Gets the degree of the spline's polynomial representation.
获得样条曲线的多项式所表示的阶数。

IsPeriodic

Specifies if the given spline is periodic.
指定给定的样条曲线是否是周期性的。

IsPlanar

Specifies if the given spline is planar.
指定给定的样条曲线是否是平面的。

IsRational

Specifies if the given spline is rational.
指定给定的样条曲线是否是有理的。

NumControlPoints

Gets the number of control points of the spline.
返回样条曲线的控制点数。

NumfFitPoints

Gets the number of fit points of the spline.
返回样条曲线的拟合点数。

For more information about editing splines, see “Modify Splines” in the AutoCAD User's Guide.

更多关于编辑样条曲线的详细信息,请参见《AutoCAD 用户手册》中的“修改样条曲线”。

更改样条曲线上的控制点

This example creates a spline and then changes the first control point for the spline.

本例创建一条样条曲线,然后更改该样条曲线的第一个控制点。

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
 
<CommandMethod("EditSpline")> _
Public Sub EditSpline()
  '' 获得当前文档和数据库   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)
 
      '' 创建一个 Point3d 集合    Create a Point3d Collection
      Dim acPt3dColl As Point3dCollection = New Point3dCollection()
      acPt3dColl.Add(New Point3d(1, 1, 0))
      acPt3dColl.Add(New Point3d(5, 5, 0))
      acPt3dColl.Add(New Point3d(10, 0, 0))
 
      ''设置起始和终止切向   Set the start and end tangency
      Dim acStartTan As Vector3d = New Vector3d(0.5, 0.5, 0)
      Dim acEndTan As Vector3d = New Vector3d(0.5, 0.5, 0)
 
      ''创建样条曲线   Create a spline
      Dim acSpline As Spline = New Spline(acPt3dColl, _
                                          acStartTan, _
                                          acEndTan, 4, 0)
 
      acSpline.SetDatabaseDefaults()
 
      '' 设置控制点   Set a control point
      acSpline.SetControlPointAt(0, New Point3d(0, 3, 0))
 
      '' 添加新对象到块表记录和事务中   Add the new object to the block table record and the transaction
      acBlkTblRec.AppendEntity(acSpline)
      acTrans.AddNewlyCreatedDBObject(acSpline, True)
 
      '' 保存新对象到数据库中   Save the new objects 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("EditSpline")]
public static void EditSpline()
{
  // 获得当前文档和数据库   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;
 
      // Create a Point3d Collection
      Point3dCollection acPt3dColl = new Point3dCollection();
      acPt3dColl.Add(new Point3d(1, 1, 0));
      acPt3dColl.Add(new Point3d(5, 5, 0));
      acPt3dColl.Add(new Point3d(10, 0, 0));
 
      // Set the start and end tangency
      Vector3d acStartTan = new Vector3d(0.5, 0.5, 0);
      Vector3d acEndTan = new Vector3d(0.5, 0.5, 0);
 
      // Create a spline
      Spline acSpline = new Spline(acPt3dColl,
                                   acStartTan,
                                   acEndTan, 4, 0);
 
      acSpline.SetDatabaseDefaults();
 
      // Set a control point
      acSpline.SetControlPointAt(0, new Point3d(0, 3, 0));
 
      // 添加新对象到块表记录和事务中   Add the new object to the block table record and the transaction
      acBlkTblRec.AppendEntity(acSpline);
      acTrans.AddNewlyCreatedDBObject(acSpline, true);
 
      // 保存新对象到数据库中   Save the new objects to the database
      acTrans.Commit();
  }
}
VBA/ActiveX 代码参考