i just change from vba cad to .net.
it's so difficult.
my code draw polyline then addvextex until escape command
but have problem at red code
if i haven't red code i can't see polyline in screen autocad
if i have it i can not addvextex and error
Attachment 106668
any idea for issue??
+ i want to see polyline in autocad
tks all.
Code:
Imports AutoCAD
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports System
Imports System.Windows.Forms
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Public Class THU
Public Const WidthFactor As Integer = -10
<CommandMethod("vepl")> _
Public Sub VEPOLY()
Dim dblNew(0 To 2) As Double
Dim lngLastVertex As Long
Dim varPick As Object
Dim varPick1 As Object
Dim varWCS As Object
Dim dblPoints(3) As Double
Dim Lineweight As Double
Dim varpoint, varpoint1 As Object
Dim i, min, max, NoOfIndices
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim pPtRes As PromptPointResult
Dim pPtOpts As PromptPointOptions = New PromptPointOptions("")
On Error Resume Next
lngLastVertex = 2
Lineweight = ThisDrawing.ActiveLayer.Lineweight * WidthFactor
'' Prompt for the start point
pPtOpts.Message = vbLf & "Enter the start point of the line: "
pPtRes = doc.Editor.GetPoint(pPtOpts)
Dim ptStart As Point3d = pPtRes.Value
Dim StarPt As Point2d = 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
'' Prompt for the end point
pPtOpts.Message = vbLf & "\nSelect Next Point: "
'pPtOpts.SetMessageAndKeywords("\nSelect Next Point: or Exit [Y]", "Yes")
'pPtOpts.AppendKeywordsToMessage = True
'pPtOpts.AllowArbitraryInput = True
pPtOpts.UseBasePoint = True
pPtOpts.BasePoint = ptStart
pPtRes = doc.Editor.GetPoint(pPtOpts)
Dim PtEnd As Point3d = pPtRes.Value
Dim EndPT As Point2d = New Point2d(pPtRes.Value.X, pPtRes.Value.Y)
If pPtRes.Status = PromptStatus.Cancel Then Exit Sub
Using acTrans As Transaction = db.TransactionManager.StartTransaction
Dim acBlkTbl As BlockTable = acTrans.GetObject(db.BlockTableId, OpenMode.ForRead)
'' Open the Block table record Model space for write
Dim acBlkTblRec As BlockTableRecord = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
Dim acPoly As Polyline = New Polyline()
acPoly.SetDatabaseDefaults()
acPoly.AddVertexAt(0, StarPt, 0, 0, 0)
acPoly.AddVertexAt(1, EndPT, 0, 0, 0)
'' Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acPoly)
acTrans.AddNewlyCreatedDBObject(acPoly, True)
acTrans.Commit()
'ed.UpdateScreen()
Do
pPtOpts.Message = vbLf & "Enter the Next point of the Polyline: "
pPtOpts.UseBasePoint = True
pPtOpts.BasePoint = PtEnd
pPtRes = doc.Editor.GetPoint(pPtOpts)
Dim PtNext As Point2d = New Point2d(pPtRes.Value.X, pPtRes.Value.Y)
If pPtRes.Status = PromptStatus.Cancel Then
PtEnd = pPtRes.Value
Exit Do
End If
'acPoly.AddVertexAt(acPoly.NumberOfVertices + 1, PtNext, 0, 0, 0)
'ed.Regen()
acPoly.AddVertexAt(lngLastVertex, PtNext, 0, 0, 0)
lngLastVertex = lngLastVertex + 1
acBlkTblRec.AppendEntity(acPoly)
acTrans.AddNewlyCreatedDBObject(acPoly, True)
acTrans.Commit()
Loop While 1
'AddHandler acPoly.Modified, AddressOf acpolymod
acTrans.Commit()
End Using
End Sub