03-04 創建和編輯AutoCAD實體(四) 編輯二維命名對象 (8)

 

10、Edit Splines編輯樣條曲線

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.

獲取樣條曲線給定索引位置的擬合點(只一個擬合點。要查詢樣條曲線的所有擬合點,應使用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 theAutoCAD User's Guide.

更多關於編輯樣條曲線的內容,見AutoCAD用戶指南裏“修改樣條曲線”一節。

 

Change a control point on a spline 修改樣條曲線的控制點

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)

 

      '' 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)

 

      '' 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);

 

      // 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 Code Reference

Sub EditSpline()

    ' Create the spline

    Dim splineObj As AcadSpline

    Dim startTan(0 To 2) As Double

    Dim endTan(0 To 2) As Double

    Dim fitPoints(0 To 8) As Double

 

    startTan(0) = 0.5: startTan(1) = 0.5: startTan(2) = 0

    endTan(0) = 0.5: endTan(1) = 0.5: endTan(2) = 0

    fitPoints(0) = 1: fitPoints(1) = 1: fitPoints(2) = 0

    fitPoints(3) = 5: fitPoints(4) = 5: fitPoints(5) = 0

    fitPoints(6) = 10: fitPoints(7) = 0: fitPoints(8) = 0

    Set splineObj = ThisDrawing.ModelSpace. _

                                  AddSpline(fitPoints, startTan, endTan)

    splineObj.Update

 

    ' Change the coordinate of the first fit point

    Dim controlPoint(0 To 2) As Double

    controlPoint(0) = 0

    controlPoint(1) = 3

    controlPoint(2) = 0

    splineObj.SetControlPoint 0, controlPoint

    splineObj.Update

End Sub

 

發佈了4 篇原創文章 · 獲贊 20 · 訪問量 16萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章