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

 

9、Edit Polylines編輯多段線

2D and 3D polylines, rectangles, polygons, donuts, and 3D polygon meshes are all polyline variants and are edited in the same way.

二維多段線和三維多段線、矩形、多邊形、圓環以及三維多邊形網格都是多段線的變體,可以使用相同的方法對其進行編輯。

AutoCAD recognizes both fit polylines and spline-fit polylines. A spline-fit polyline uses a curve fit, similar to a B-spline. There are two kinds of spline-fit polylines: quadratic and cubic. Both polylines are controlled by the SPLINETYPE system variable. A fit polyline uses standard curves for curve fit and utilizes any tangent directions set on any given vertex.

AutoCAD能夠識別擬合多段線和樣條曲線擬合多段線。樣條曲線擬合多段線使用曲線擬合而成,類似於B樣條曲線。有兩種樣條曲線擬合多段線:二次的和三次的,兩種多段線均由系統變量SPLINETYPE控制。擬合多段線使用標準曲線利用在給定頂點設置切線方向擬合而成。

To edit a polyline, use the properties and methods of the Polyline, Polyline2d, or Polyline3d object. Use the following properties and methods to open or close a polyline, change the coordinates of a polyline vertex, or add a vertex:

使用Polyline對象、 Polyline2d對象或Polyline3d對象的屬性和方法來編輯多段線。下列屬性和方法用於開放或閉合多段線、改變多段線頂點座標、增加頂點等:

Closed 屬性

Opens or closes the polyline. 開放或閉合多段線;

ConstantWidth 屬性

Sets the constant width for a lightweight and 2D polyline. 設置輕量級和2D多段線寬度常量;

AppendVertex 方法

Adds a vertex to a 2D or 3D polyline. 給2D或3D多段線增加頂點;

AddVertexAt 方法

Adds a vertex to a lightweight polyline. 給輕量級多段線增加頂點;

ReverseCurve 方法

Reverses the direction of the polyline. 掉換多段線方向;

 

Use the following methods to update the bulge or width of a polyline:

下列方法用於修改多段線的凸度或寬度:

SetBulgeAt 方法

Sets the bulge of a light polyline, given the segment index. 給定線段索引,設置多段線的凸度;

SetStartWidthAt 方法

Sets the start width of a lightweight polyline, given the segment index. 給定線段索引,設置輕量級多段線的起始寬度;

Straighten方法

Straightens a 2D or 3D polyline. 拉直2D或3D多段線

For more information about editing polylines, see “Modify or Join Polyline” in theUser's Guide.

關於編輯多段線的更多內容,見AutoCAD用戶指南中的“修改或連結多段線”。

Edit a polyline 編輯多段線

This example creates a lightweight polyline. It then adds a bulge to the third segment of the polyline, appends a vertex to the polyline, changes the width of the last segment, and finally closes the polyline.

本例創建一條輕量級多段線,然後將第三條線段變成曲線(添加凸度)、追加一個頂點、修改最後那條線段的寬度,最後閉合該多段線。

VB.NET

Imports Autodesk.AutoCAD.Runtime

Imports Autodesk.AutoCAD.ApplicationServices

Imports Autodesk.AutoCAD.DatabaseServices

Imports Autodesk.AutoCAD.Geometry

 

<CommandMethod("EditPolyline")> _

Public Sub EditPolyline()

  '' 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 lightweight polyline

      Dim acPoly As Polyline = New Polyline()

      acPoly.AddVertexAt(0, New Point2d(1, 1), 0, 0, 0)

      acPoly.AddVertexAt(1, New Point2d(1, 2), 0, 0, 0)

      acPoly.AddVertexAt(2, New Point2d(2, 2), 0, 0, 0)

      acPoly.AddVertexAt(3, New Point2d(3, 2), 0, 0, 0)

      acPoly.AddVertexAt(4, New Point2d(4, 4), 0, 0, 0)

 

      '' Add the new object to the block table record and the transaction

      acBlkTblRec.AppendEntity(acPoly)

      acTrans.AddNewlyCreatedDBObject(acPoly, True)

 

      '' Sets the bulge at index 3

      acPoly.SetBulgeAt(3, -0.5)

 

      '' Add a new vertex

      acPoly.AddVertexAt(5, New Point2d(4, 1), 0, 0, 0)

 

      '' Sets the start and end width at index 4

      acPoly.SetStartWidthAt(4, 0.1)

      acPoly.SetEndWidthAt(4, 0.5)

 

      '' Close the polyline

      acPoly.Closed = 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("EditPolyline")]

public static void EditPolyline()

{

  // 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 lightweight polyline創建輕型多段線

      Polyline acPoly = new Polyline();

      acPoly.AddVertexAt(0, new Point2d(1, 1), 0, 0, 0);

      acPoly.AddVertexAt(1, new Point2d(1, 2), 0, 0, 0);

      acPoly.AddVertexAt(2, new Point2d(2, 2), 0, 0, 0);

      acPoly.AddVertexAt(3, new Point2d(3, 2), 0, 0, 0);

      acPoly.AddVertexAt(4, new Point2d(4, 4), 0, 0, 0);

 

      // Add the new object to the block table record and the transaction

      //將新對象添加到塊表記錄和事務

      acBlkTblRec.AppendEntity(acPoly);

      acTrans.AddNewlyCreatedDBObject(acPoly, true);

 

      // Sets the bulge at index 3設置線段3的凸度

      acPoly.SetBulgeAt(3, -0.5);

 

      // Add a new vertex添加新頂點

      acPoly.AddVertexAt(5, new Point2d(4, 1), 0, 0, 0);

 

      // Sets the start and end width at index 4設置線段4的起止寬度

      acPoly.SetStartWidthAt(4, 0.1);

      acPoly.SetEndWidthAt(4, 0.5);

 

      // Close the polyline閉合多段線

      acPoly.Closed = true;

 

      // Save the new objects to the database提交修改

      acTrans.Commit();

  }

}

VBA/ActiveX Code Reference

Sub EditPolyline()

    Dim plineObj As AcadLWPolyline

    Dim points(0 To 9) As Double

 

    ' Define the 2D polyline points

    points(0) = 1: points(1) = 1

    points(2) = 1: points(3) = 2

    points(4) = 2: points(5) = 2

    points(6) = 3: points(7) = 2

    points(8) = 4: points(9) = 4

 

    ' Create a light weight Polyline object

    Set plineObj = ThisDrawing.ModelSpace. _

                                 AddLightWeightPolyline(points)

 

    ' Add a bulge to segment 3

    plineObj.SetBulge 3, -0.5

 

    ' Define the new vertex

    Dim newVertex(0 To 1) As Double

    newVertex(0) = 4: newVertex(1) = 1

 

    ' Add the vertex to the polyline

    plineObj.AddVertex 5, newVertex

 

    ' Set the width of the new segment

    plineObj.SetWidth 4, 0.1, 0.5

 

    ' Close the polyline

    plineObj.Closed = True

    plineObj.Update

End Sub

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章