Code:
Dim pPtRes As PromptPointResult
Dim colPt As Point2dCollection = New Point2dCollection
Dim pPtOpts As PromptPointOptions = New PromptPointOptions("") '' Prompt for the first point
pPtOpts.Message = vbLf & "Bitte den ersten Punkt festlgen: "
pPtRes = acDoc.Editor.GetPoint(pPtOpts)
colPt.Add(New Point2d(pPtRes.Value.X, pPtRes.Value.Y))
'' Exit if the user presses ESC or cancels the command
If pPtRes.Status = PromptStatus.Cancel Then Exit Sub
Dim i As Integer = 1
If Err.Number = 0 Then
Do Until Err.Number <> 0
'i = i + 2
'' Prompt for the next points
pPtOpts.Message = vbLf & "Bitte einen nächsten Punkt festlgen: "
'' Use the previous point as the base point
pPtOpts.UseBasePoint = True
pPtOpts.BasePoint = pPtRes.Value
pPtRes = acDoc.Editor.GetPoint(pPtOpts)
colPt.Add(New Point2d(pPtRes.Value.X, pPtRes.Value.Y))
If pPtRes.Status = PromptStatus.Cancel Then Exit Sub
'' Increment the counter
i = i + 1
Loop
On Error Resume Next
'' Create a polyline with 5 points
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)
Dim acPoly As Polyline = New Polyline()
acPoly.AddVertexAt(i, colPt(0), 0, 0, 0)
'Dim acPoly As Polyline = New Polyline()
'acPoly.AddVertexAt(0, colPt(0), 0, 0, 0)
'acPoly.AddVertexAt(1, colPt(1), 0, 0, 0)
'acPoly.AddVertexAt(2, colPt(2), 0, 0, 0)
'acPoly.AddVertexAt(3, colPt(3), 0, 0, 0)
'acPoly.AddVertexAt(4, colPt(4), 0, 0, 0)
'' Close the polyline
Dim lngResp As Long
lngResp = MsgBox("Möchten Sie die Polylinie schließen?", MsgBoxStyle.YesNo, "Polylinie schließen Modus")
If lngResp = 6 Then
acPoly.Closed = True
acPoly.Color = Color.FromRgb(255, 0, 0)
End If
'' Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acPoly)
acTrans.AddNewlyCreatedDBObject(acPoly, True)
'' Save the new object to the database
acTrans.Commit()
End Using
End If